Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix decryption key padding for ed25519 #165

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const getSecpKeyFromEd25519 = (

const secpKeyPair = secp256k1Curve.keyFromPrivate(bufferKey);

if (bufferKey.length < 32) {
throw new Error(`Key length must be less than 32. got ${bufferKey.length}`);
if (bufferKey.length !== 32) {
throw new Error(`Key length must be equal to 32. got ${bufferKey.length}`);
}
return {
scalar: secpKeyPair.getPrivate(),
Expand Down Expand Up @@ -214,7 +214,7 @@ export const decryptSeedData = async (seedBase64: string, finalUserKey: BN) => {
const seedUtf8 = Buffer.from(seedBase64, "base64").toString("utf-8");
const seedJson = JSON.parse(seedUtf8) as EncryptedSeed;
const bufferMetadata = { ...encParamsHexToBuf(seedJson.metadata), mode: "AES256" };
const bufferKey = decryptionKey.scalar.toArrayLike(Buffer);
const bufferKey = decryptionKey.scalar.toArrayLike(Buffer, "be", 32);
const decText = await decrypt(bufferKey, {
...bufferMetadata,
ciphertext: Buffer.from(seedJson.enc_text, "hex"),
Expand Down