I've written this working NodeJS/Javascript function:
/*
* Calculate the Symmetric Key from the Public and Secret keys from two
* different key pairs.
*
* Note: symmetric_key(publicA, secretB) == symmetric_key(publicB, secretA)
*/
function symmetric_key(pkey, skey) {
const ephemeral = crypto.createECDH('secp256k1');
ephemeral.setPublicKey(pkey);
const centre = crypto.createECDH('secp256k1');
centre.setPrivateKey(skey);
return centre.computeSecret(ephemeral.getPublicKey());
}
I'm trying to understand how I can use the Rust secp256k1
library to do the same.
Looking at secp256k1::SecretKey's methods I cannot see a direct equivalent.
- What is that library's version of
computeSecret()
called? - If it doesn't have an analogous method, how can I compute the required secret?