dfinity / rosetta-client

Apache License 2.0
44 stars 11 forks source link

generated incorrect public key by function key_to_pub_key #59

Closed cloverzrg closed 3 years ago

cloverzrg commented 3 years ago

The function key_to_pub_key use tweetnacl.sign.keyPair.fromSecretKey to generate public key, but the tweetnacl.sign.keyPair.fromSecretKey just copy the last 32bit as it's public key.

nacl.sign.keyPair.fromSecretKey = function(secretKey) {
  checkArrayTypes(secretKey);
  if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
    throw new Error('bad secret key size');
  var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
  for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];      <---
  return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
};