From b11cb481e92ca6c75a70546b5f17dc80b4deede5 Mon Sep 17 00:00:00 2001 From: Dmytro Vynnyk Date: Mon, 16 Dec 2024 11:45:31 +0100 Subject: [PATCH] Fix ed25519 private key length validation --- src/types/keypair/ed25519/PrivateKey.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types/keypair/ed25519/PrivateKey.ts b/src/types/keypair/ed25519/PrivateKey.ts index bfebf4a3e..b3d74e489 100644 --- a/src/types/keypair/ed25519/PrivateKey.ts +++ b/src/types/keypair/ed25519/PrivateKey.ts @@ -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); @@ -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');