Skip to content

Commit

Permalink
chore: add acct path key to change pin util
Browse files Browse the repository at this point in the history
  • Loading branch information
r4mmer committed May 12, 2023
1 parent 14a5117 commit a4e1bc0
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,28 +599,26 @@ const wallet = {
*/
changeEncryptionPin(accessData: IWalletAccessData, oldPin: string, newPin: string): IWalletAccessData {
const data = _.cloneDeep(accessData);
if (!(data.mainKey || data.authKey)) {
if (!(data.mainKey || data.authKey || data.acctPathKey)) {
throw new Error('No data to change');
}

if (data.mainKey) {
try {
const mainKey = decryptData(data.mainKey, oldPin);
const newEncryptedMainKey = encryptData(mainKey, newPin);
data.mainKey = newEncryptedMainKey;
} catch(err: unknown) {
throw new Error('Old pin is incorrect.');
}
const mainKey = decryptData(data.mainKey, oldPin);
const newEncryptedMainKey = encryptData(mainKey, newPin);
data.mainKey = newEncryptedMainKey;
}

if (data.authKey) {
try {
const authKey = decryptData(data.authKey, oldPin);
const newEncryptedAuthKey = encryptData(authKey, newPin);
data.authKey = newEncryptedAuthKey;
} catch(err: unknown) {
throw new Error('Old pin is incorrect.');
}
const authKey = decryptData(data.authKey, oldPin);
const newEncryptedAuthKey = encryptData(authKey, newPin);
data.authKey = newEncryptedAuthKey;
}

if (data.acctPathKey) {
const acctPathKey = decryptData(data.acctPathKey, oldPin);
const newEncryptedAcctPathKey = encryptData(acctPathKey, newPin);
data.acctPathKey = newEncryptedAcctPathKey;
}

return data;
Expand All @@ -641,13 +639,9 @@ const wallet = {
throw new Error('No data to change');
}

try {
const words = decryptData(data.words, oldPassword);
const newEncryptedWords = encryptData(words, newPassword);
data.words = newEncryptedWords;
} catch(err: unknown) {
throw new Error('Old password is incorrect.');
}
const words = decryptData(data.words, oldPassword);
const newEncryptedWords = encryptData(words, newPassword);
data.words = newEncryptedWords;

return data;
},
Expand Down

0 comments on commit a4e1bc0

Please sign in to comment.