Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created October 5, 2022 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/990699b5ac0cd1345d068b79cce9a8df to your computer and use it in GitHub Desktop.
Save CMCDragonkai/990699b5ac0cd1345d068b79cce9a8df to your computer and use it in GitHub Desktop.
Validate Public Key #ed25519
import * as nobleEd25519 from '@noble/ed25519';
/**
* Checks if the public key is a point on the Ed25519 curve
*/
function validatePublicKey(publicKey: Buffer): boolean {
try {
nobleEd25519.Point.fromHex(publicKey);
return true;
} catch {
// If there's an error, it is an invalid public key
return false;
}
}
import sodium from 'sodium-native';
/**
* Checks if the public key is a point on the Ed25519 curve
*/
function validatePublicKey(publicKey: Buffer): boolean {
return sodium.crypto_core_ed25519_is_valid_point(publicKey);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment