diff --git a/src/crypto/public_key/elliptic/eddsa.js b/src/crypto/public_key/elliptic/eddsa.js index fdde149c..8e431f79 100644 --- a/src/crypto/public_key/elliptic/eddsa.js +++ b/src/crypto/public_key/elliptic/eddsa.js @@ -32,17 +32,18 @@ nacl.hash = bytes => new Uint8Array(sha512().update(bytes).digest()); /** * Sign a message using the provided key - * @param {module:type/oid} oid Elliptic curve object identifier - * @param {module:enums.hash} hash_algo Hash algorithm used to sign - * @param {Uint8Array} m Message to sign - * @param {Uint8Array} d Private key used to sign - * @param {Uint8Array} hashed The hashed message + * @param {module:type/oid} oid Elliptic curve object identifier + * @param {module:enums.hash} hash_algo Hash algorithm used to sign + * @param {Uint8Array} message Message to sign + * @param {Uint8Array} publicKey Public key + * @param {Uint8Array} privateKey Private key used to sign the message + * @param {Uint8Array} hashed The hashed message * @returns {{R: Uint8Array, - * S: Uint8Array}} Signature of the message + * S: Uint8Array}} Signature of the message * @async */ -async function sign(oid, hash_algo, m, d, hashed) { - const { secretKey } = nacl.sign.keyPair.fromSeed(d); +async function sign(oid, hash_algo, message, publicKey, privateKey, hashed) { + const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]); const signature = nacl.sign.detached(hashed, secretKey); // EdDSA signature params are returned in little-endian format return { diff --git a/src/crypto/signature.js b/src/crypto/signature.js index 7d694478..cbc1e05d 100644 --- a/src/crypto/signature.js +++ b/src/crypto/signature.js @@ -132,8 +132,9 @@ export default { } case enums.publicKey.eddsa: { const oid = key_params[0]; + const Q = key_params[1].toUint8Array('be', 33); 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([ util.Uint8Array_to_MPI(signature.R), util.Uint8Array_to_MPI(signature.S)