Skip to content

Commit

Permalink
fix: port isSerializedKeyringsArray function
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Jan 24, 2024
1 parent 7e4a5f6 commit 214cf7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
hasProperty,
isObject,
isValidHexAddress,
isValidJson,
remove0x,
} from '@metamask/utils';
import { Mutex } from 'async-mutex';
Expand Down Expand Up @@ -442,7 +443,7 @@ function isSerializedKeyringsArray(
return (
typeof array === 'object' &&
Array.isArray(array) &&
array.every((value) => value.type && value.data)
array.every((value) => value.type && isValidJson(value.data))
);
}

Expand Down
8 changes: 3 additions & 5 deletions packages/keyring-controller/tests/mocks/mockEncryptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Json } from '@metamask/utils';

import type { ExportableKeyEncryptor } from '../../src/KeyringController';

export const PASSWORD = 'password123';
Expand All @@ -19,7 +17,7 @@ export const MOCK_HEX = '0xabcdef0123456789';
const MOCK_KEY = Buffer.alloc(32);
const INVALID_PASSWORD_ERROR = 'Incorrect password.';

let cacheVal: Json;
let cacheVal: string;

export default class MockEncryptor implements ExportableKeyEncryptor {
// TODO: Replace `any` with type
Expand All @@ -36,13 +34,13 @@ export default class MockEncryptor implements ExportableKeyEncryptor {
throw new Error(INVALID_PASSWORD_ERROR);
}

return cacheVal ?? {};
return JSON.parse(cacheVal) ?? {};
}

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async encryptWithKey(_key: unknown, dataObj: any) {
cacheVal = dataObj;
cacheVal = JSON.stringify(dataObj);
return {
data: MOCK_HEX,
iv: 'anIv',
Expand Down

0 comments on commit 214cf7f

Please sign in to comment.