Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide functions to get public keys from secret keys. #18

Closed
dchest opened this issue Jun 24, 2014 · 0 comments
Closed

Provide functions to get public keys from secret keys. #18

dchest opened this issue Jun 24, 2014 · 0 comments

Comments

@dchest
Copy link
Owner

dchest commented Jun 24, 2014

nacl.box.keyPair.fromSecretKey(secretKey) => // returns key pair
nacl.sign.keyPair.fromSecretKey(secretKey) => // -"-

Implementation of the first one is easy:

exports.box.keyPair.fromSecretKey = function(secretKey) {
  checkArrayTypes(secretKey);
  if (secretKey.length !== crypto_box_SECRETKEYBYTES)
    throw new Error('bad secret key size');
  var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
  crypto_scalarmult_base(pk, secretKey);
  return {publicKey: pk, secretKey: secretKey};
};

~~Sign will be ~copy of crypto_sign_keypair, which is ugly, but I don't want to refactor tweenacl.c-based code.~~ (Don't file issues when ill! Sign public key is just the second 32-byte part of the secret key).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant