Skip to content

Commit

Permalink
Merge pull request #165 from torusresearch/fix/decryption-key-padding
Browse files Browse the repository at this point in the history
fix decryption key padding for ed25519
  • Loading branch information
chaitanyapotti authored Sep 27, 2024
2 parents 7620150 + d7434a0 commit 5ccdd09
Showing 1 changed file with 3 additions and 3 deletions.
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

0 comments on commit 5ccdd09

Please sign in to comment.