Created
October 5, 2022 05:48
-
-
Save CMCDragonkai/990699b5ac0cd1345d068b79cce9a8df to your computer and use it in GitHub Desktop.
Validate Public Key #ed25519
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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