Use serialized EdDSA public key when signing instead of deriving it
This commit is contained in:
parent
fd9371a2a4
commit
a6d7c466e2
|
@ -32,17 +32,18 @@ nacl.hash = bytes => new Uint8Array(sha512().update(bytes).digest());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign a message using the provided key
|
* Sign a message using the provided key
|
||||||
* @param {module:type/oid} oid Elliptic curve object identifier
|
* @param {module:type/oid} oid Elliptic curve object identifier
|
||||||
* @param {module:enums.hash} hash_algo Hash algorithm used to sign
|
* @param {module:enums.hash} hash_algo Hash algorithm used to sign
|
||||||
* @param {Uint8Array} m Message to sign
|
* @param {Uint8Array} message Message to sign
|
||||||
* @param {Uint8Array} d Private key used to sign
|
* @param {Uint8Array} publicKey Public key
|
||||||
* @param {Uint8Array} hashed The hashed message
|
* @param {Uint8Array} privateKey Private key used to sign the message
|
||||||
|
* @param {Uint8Array} hashed The hashed message
|
||||||
* @returns {{R: Uint8Array,
|
* @returns {{R: Uint8Array,
|
||||||
* S: Uint8Array}} Signature of the message
|
* S: Uint8Array}} Signature of the message
|
||||||
* @async
|
* @async
|
||||||
*/
|
*/
|
||||||
async function sign(oid, hash_algo, m, d, hashed) {
|
async function sign(oid, hash_algo, message, publicKey, privateKey, hashed) {
|
||||||
const { secretKey } = nacl.sign.keyPair.fromSeed(d);
|
const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
|
||||||
const signature = nacl.sign.detached(hashed, secretKey);
|
const signature = nacl.sign.detached(hashed, secretKey);
|
||||||
// EdDSA signature params are returned in little-endian format
|
// EdDSA signature params are returned in little-endian format
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -132,8 +132,9 @@ export default {
|
||||||
}
|
}
|
||||||
case enums.publicKey.eddsa: {
|
case enums.publicKey.eddsa: {
|
||||||
const oid = key_params[0];
|
const oid = key_params[0];
|
||||||
|
const Q = key_params[1].toUint8Array('be', 33);
|
||||||
const d = key_params[2].toUint8Array('be', 32);
|
const d = key_params[2].toUint8Array('be', 32);
|
||||||
const signature = await publicKey.elliptic.eddsa.sign(oid, hash_algo, data, d, hashed);
|
const signature = await publicKey.elliptic.eddsa.sign(oid, hash_algo, data, Q, d, hashed);
|
||||||
return util.concatUint8Array([
|
return util.concatUint8Array([
|
||||||
util.Uint8Array_to_MPI(signature.R),
|
util.Uint8Array_to_MPI(signature.R),
|
||||||
util.Uint8Array_to_MPI(signature.S)
|
util.Uint8Array_to_MPI(signature.S)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user