# Need two EC keypairs from the same curve
sk1 <- ec_keygen()
pk1 <- as.list(sk1)$pubkey
sk2 <- ec_keygen()
pk2 <- as.list(sk2)$pubkey
# Both peers can derive the shared secret
alice <- ec_dh(sk1, pk2)
bob <- ec_dh(sk2, pk1)
Run the code above in your browser using DataCamp Workspace