ilap / pinenacl-dart

The Dart implementation of the PyNaCl API with the TweetNaCl cryptographic library
MIT License
36 stars 4 forks source link

ConvertPublicKey + SharedKey #14

Closed redDwarf03 closed 3 years ago

redDwarf03 commented 3 years ago

Hello thanks for your work

I would like to use your library to translate this js code:

const { public: ephemeralPublicKey, private: ephemeralPrivateKey} = curve25519.generateKeyPair(randomBytes(32))  
const curve25519pub = ed2curve.convertPublicKey(pubBuf)

var sharedKey = curve25519.sharedKey(ephemeralPrivateKey, curve25519pub)

But I don't know how. Is it possible with your library ?

Best

redDwarf03 commented 3 years ago

Full code https://github.com/archethic-foundation/libjs/blob/b2b22f79d91bd88d7afd9828c536af930f4c7f19/lib/crypto.js#L286

ed2curve documentation: https://www.npmjs.com/package/ed2curve

ilap commented 3 years ago

Hi,

There is a conversion utility to use ed25519 for encryption/decryption, that you can use to achieve what you want.

https://github.com/ilap/pinenacl-dart/blob/c6f9c71f1cc5c1696389c9d57e2add447ae91480/lib/src/tweetnacl/tweetnacl_ext.dart#L57

https://github.com/ilap/pinenacl-dart/blob/c6f9c71f1cc5c1696389c9d57e2add447ae91480/lib/src/tweetnacl/tweetnacl_ext.dart#L79

redDwarf03 commented 3 years ago

great. it works. thank you!