StableLib / stablelib

A stable library of useful TypeScript/JavaScript code
https://www.stablelib.com
Other
173 stars 35 forks source link

Key exchange #57

Closed e-asphyx closed 2 years ago

e-asphyx commented 2 years ago
dchest commented 2 years ago

Thanks for the PR! I think this particular key agreement from libsodium should be a separate package rather than making x25519 package depend on blake2, and having two different methods for users to get keys.

Could you restructure it as a separate package? It can be just a copy-paste of most of this code. The name can be, X25519Blake2KeyAgreement for the class and x25519blake2. I see that it doesn't satisfy the KeyAgreement interface due to having two keys, but I think it's fine.

Also, I'd like to rename rx and tx to make their purpose clearer:

The shared secret key rx should be used by the server to receive data from the client, whereas tx should be used for data flowing in the opposite direction.

Can be sendingKey and receivingKey, perhaps? (Or whatever "r" and "t" mean.)