Skip to content

Commit b59ee0c

Browse files
committed
fix: do not override keyFromPassword derivation options
1 parent 98e2cd4 commit b59ee0c

File tree

2 files changed

+1
-70
lines changed

2 files changed

+1
-70
lines changed

app/scripts/lib/encryptor-factory.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -187,44 +187,6 @@ describe('encryptorFactory', () => {
187187
},
188188
);
189189
});
190-
191-
it('should call browser-passworder.keyFromPassword with overriden opts', async () => {
192-
const encryptor = encryptorFactory(mockIterations);
193-
194-
const mockResult = {
195-
key: 'key',
196-
derivationOptions: {
197-
algorithm: 'PBKDF2',
198-
params: {
199-
iterations: mockIterations,
200-
},
201-
},
202-
};
203-
204-
// @ts-expect-error The key type is a mock type and not valid.
205-
mockBrowserPassworder.keyFromPassword.mockResolvedValue(mockResult);
206-
207-
expect(
208-
await encryptor.keyFromPassword(
209-
mockPassword,
210-
mockSalt,
211-
true,
212-
undefined,
213-
),
214-
).toBe(mockResult);
215-
216-
expect(mockBrowserPassworder.keyFromPassword).toHaveBeenCalledWith(
217-
mockPassword,
218-
mockSalt,
219-
true,
220-
{
221-
algorithm: 'PBKDF2',
222-
params: {
223-
iterations: mockIterations,
224-
},
225-
},
226-
);
227-
});
228190
});
229191

230192
describe('isVaultUpdated', () => {

app/scripts/lib/encryptor-factory.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
exportKey,
1212
generateSalt,
1313
EncryptionKey,
14-
KeyDerivationOptions,
1514
} from '@metamask/browser-passworder';
1615

1716
/**
@@ -53,36 +52,6 @@ const encryptWithDetailFactory =
5352
},
5453
});
5554

56-
/**
57-
* A factory function for the keyFromPassword method of the browser-passworder library,
58-
* that generates a key from a password and a salt.
59-
*
60-
* This factory function overrides the default key derivation options with the specified
61-
* number of iterations, unless existing key derivation options are passed in.
62-
*
63-
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
64-
* @returns A function that generates a key with a potentially overriden number of iterations.
65-
*/
66-
const keyFromPasswordFactory =
67-
(iterations: number) =>
68-
async (
69-
password: string,
70-
salt: string,
71-
exportable?: boolean,
72-
opts?: KeyDerivationOptions,
73-
) =>
74-
keyFromPassword(
75-
password,
76-
salt,
77-
exportable,
78-
opts ?? {
79-
algorithm: 'PBKDF2',
80-
params: {
81-
iterations,
82-
},
83-
},
84-
);
85-
8655
/**
8756
* A factory function for the isVaultUpdated method of the browser-passworder library,
8857
* that checks if the given vault was encrypted with the given number of iterations.
@@ -114,7 +83,7 @@ export const encryptorFactory = (iterations: number) => ({
11483
decrypt,
11584
decryptWithKey,
11685
decryptWithDetail,
117-
keyFromPassword: keyFromPasswordFactory(iterations),
86+
keyFromPassword,
11887
isVaultUpdated: isVaultUpdatedFactory(iterations),
11988
importKey,
12089
exportKey,

0 commit comments

Comments
 (0)