mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 01:25:48 +00:00
Bump version: 0.7.3
This commit is contained in:
@@ -9,7 +9,7 @@ const {Sha512, cached} = require('./utils');
|
||||
/*
|
||||
@param {Array} seed bytes
|
||||
*/
|
||||
function deriveEdKeyPairSeed(seed) {
|
||||
function deriveEdKeyPairSecret(seed) {
|
||||
return new Sha512().add(seed).first256();
|
||||
}
|
||||
|
||||
@@ -45,17 +45,16 @@ class Ed25519Pair extends KeyPair {
|
||||
}
|
||||
|
||||
@cached
|
||||
key() {
|
||||
if (this.seedBytes) {
|
||||
const seed256 = deriveEdKeyPairSeed(this.seedBytes);
|
||||
return Ed25519.keyFromSecret(seed256);
|
||||
}
|
||||
return Ed25519.keyFromPublic(this.pubKeyCanonicalBytes().slice(1));
|
||||
pubKeyCanonicalBytes() {
|
||||
return [0xED].concat(this.key().pubBytes());
|
||||
}
|
||||
|
||||
@cached
|
||||
pubKeyCanonicalBytes() {
|
||||
return [0xED].concat(this.key().pubBytes());
|
||||
key() {
|
||||
if (this.seedBytes) {
|
||||
return Ed25519.keyFromSecret(deriveEdKeyPairSecret(this.seedBytes));
|
||||
}
|
||||
return Ed25519.keyFromPublic(this.pubKeyCanonicalBytes().slice(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,18 +79,6 @@ class K256Pair extends KeyPair {
|
||||
return this._createSignature(message).toDER();
|
||||
}
|
||||
|
||||
_createSignature(message) {
|
||||
return this.key().sign(this.hashMessage(message), {canonical: true});
|
||||
}
|
||||
|
||||
/*
|
||||
@param {Array<Byte>} message - (bytes)
|
||||
@return {Array<Byte>} - 256 bit hash of the message
|
||||
*/
|
||||
hashMessage(message) {
|
||||
return hashjs.sha512().update(message).digest().slice(0, 32);
|
||||
}
|
||||
|
||||
/*
|
||||
@param {Array<Byte>} message - bytes
|
||||
@param {Array<Byte>} signature - DER encoded signature bytes
|
||||
@@ -105,6 +93,23 @@ class K256Pair extends KeyPair {
|
||||
}
|
||||
}
|
||||
|
||||
@cached
|
||||
pubKeyCanonicalBytes() {
|
||||
return this.key().getPublic().encodeCompressed();
|
||||
}
|
||||
|
||||
_createSignature(message) {
|
||||
return this.key().sign(this.hashMessage(message), {canonical: true});
|
||||
}
|
||||
|
||||
/*
|
||||
@param {Array<Byte>} message - (bytes)
|
||||
@return {Array<Byte>} - 256 bit hash of the message
|
||||
*/
|
||||
hashMessage(message) {
|
||||
return hashjs.sha512().update(message).digest().slice(0, 32);
|
||||
}
|
||||
|
||||
@cached
|
||||
key() {
|
||||
if (this.seedBytes) {
|
||||
@@ -114,10 +119,6 @@ class K256Pair extends KeyPair {
|
||||
return secp256k1.keyFromPublic(this.pubKeyCanonicalBytes());
|
||||
}
|
||||
|
||||
@cached
|
||||
pubKeyCanonicalBytes() {
|
||||
return this.key().getPublic().encodeCompressed();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user