Skip to content

Commit

Permalink
ts-sdk: fix ed25519 private key length to match nacl (MystenLabs#4911)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqvq authored Sep 30, 2022
1 parent 30d2fba commit 755d692
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sdk/typescript/src/cryptography/ed25519-keypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ export class Ed25519Keypair implements Keypair {
if (!isValidHardenedPath(path)) {
throw new Error('Invalid derivation path');
}
const { key } = derivePath(path, mnemonicToSeedHex(mnemonics));
return new Ed25519Keypair({ publicKey: getPublicKey(key), secretKey: key });
const { key } = derivePath(path, mnemonicToSeedHex(mnemonics));

// Ed25519 private key returned here has 32 bytes. NaCl expects 64 bytes where the last 32 bytes are the public key.
let fullPrivateKey = new Uint8Array(64);
fullPrivateKey.set(key);
fullPrivateKey.set(getPublicKey(key, false), 32);

return new Ed25519Keypair({ publicKey: getPublicKey(key), secretKey: fullPrivateKey });
}
}

0 comments on commit 755d692

Please sign in to comment.