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)};
};
The function
key_to_pub_key
usetweetnacl.sign.keyPair.fromSecretKey
to generate public key, but thetweetnacl.sign.keyPair.fromSecretKey
just copy the last 32bit as it's public key.