Is it possible to add and expose a method that will allow generation of shared secrets using ECDH?
Method would probably look like this:
// Alice's side
ethereum
.request({
method: 'eth_createSharedSecret',
params: 'bob_pubKey', // shared with Alice by Bob
})
.then((sharedSecret) =>
console.log('your shared secret is', sharedSecret);
// hash sharedSecret
// encrypt message via AES with hashedSharedSecret
// share encrypted message via (in)secure channel
)
.catch((error) => console.log(error.message));
// Bob's side, received encryptedMessage from Alice
ethereum
.request({
method: 'eth_createSharedSecret',
params: 'alice_pubKey', // Shared with Bob by Alice
})
.then((sharedSecret) =>
console.log('your shared secret is', sharedSecret);
// hash sharedSecret
// decrypt message via AES with hashedSharedSecret
// Bob reads message
)
.catch((error) => console.log(error.message));
eth_createSharedSecret would run a scalar multiplication on Alice’s pubKey.X
, Bob’s pubKey.Y
and Alice’s privateKey
; on the other side, Bob’s pubKey.X
, Alice’s pubKey.Y
and Bob’s privateKey
. This should produce the same sharedSecret
.