Skip to content

Commit

Permalink
Fix ed25519 private key length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Comp0te committed Dec 16, 2024
1 parent 91cfe66 commit b11cb48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/types/keypair/ed25519/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class PrivateKey implements PrivateKeyInternal {
* @throws Error if the byte array length is not 64.
*/
static fromBytes(key: Uint8Array): PrivateKey {
if (key.length !== 64) {
if (key.length !== 32) {
throw new Error(`Invalid key size: expected 64 bytes, got ${key.length}`);
}
return new PrivateKey(key);
Expand All @@ -72,9 +72,9 @@ export class PrivateKey implements PrivateKeyInternal {
* @throws Error if the hex string length is not 128 characters.
*/
static fromHex(keyHex: string): PrivateKey {
if (keyHex.length !== 128) {
if (keyHex.length !== 64) {
throw new Error(
`Invalid hex string length: expected 128 characters, got ${keyHex.length}`
`Invalid hex string length: expected 64 characters, got ${keyHex.length}`
);
}
const keyBytes = Buffer.from(keyHex, 'hex');
Expand Down

0 comments on commit b11cb48

Please sign in to comment.