Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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 jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ module.exports = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 72.41,
branches: 71.42,
functions: 92.85,
lines: 90.87,
statements: 91.08,
lines: 90.68,
statements: 90.9,
},
},
preset: 'ts-jest',
Expand Down
35 changes: 12 additions & 23 deletions src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ describe('KeyringController', () => {
const previousAccounts = await keyringController.getAccounts();
const keyring = await keyringController.addNewKeyring(
KeyringType.Simple,
{ privateKeys: [privateKey] },
[privateKey],
);

const keyringAccounts = await keyring?.getAccounts();
Expand All @@ -473,15 +473,6 @@ describe('KeyringController', () => {
expect(allAccounts).toStrictEqual(expectedAllAccounts);
});

it('should throw an error when attempting to add simple key pair without private keys', async () => {
const keyringController = await initializeKeyringController({
password: PASSWORD,
});
await expect(async () =>
keyringController.addNewKeyring(KeyringType.Simple),
).rejects.toThrow('Private keys missing');
});

it('should add HD Key Tree without mnemonic passed as an argument', async () => {
const keyringController = await initializeKeyringController({
password: PASSWORD,
Expand Down Expand Up @@ -663,9 +654,9 @@ describe('KeyringController', () => {
const accountsBeforeAdding = await keyringController.getAccounts();

// Add a new keyring with one account
await keyringController.addNewKeyring(KeyringType.Simple, {
privateKeys: [account.privateKey],
});
await keyringController.addNewKeyring(KeyringType.Simple, [
account.privateKey,
]);
expect(keyringController.keyrings).toHaveLength(2);

// remove that account that we just added
Expand All @@ -688,9 +679,9 @@ describe('KeyringController', () => {
};

// Add a new keyring with one account
await keyringController.addNewKeyring(KeyringType.Simple, {
privateKeys: [account.privateKey],
});
await keyringController.addNewKeyring(KeyringType.Simple, [
account.privateKey,
]);

// We should have 2 keyrings
expect(keyringController.keyrings).toHaveLength(2);
Expand Down Expand Up @@ -823,7 +814,7 @@ describe('KeyringController', () => {

const keyring = await keyringController.addNewKeyring(
KeyringType.Simple,
{ privateKeys: [privateKey] },
[privateKey],
);

const getAppKeyAddressSpy = sinon.spy(
Expand Down Expand Up @@ -857,9 +848,7 @@ describe('KeyringController', () => {
const address = '0x01560cd3bac62cc6d7e6380600d9317363400896';
const privateKey =
'0xb8a9c05beeedb25df85f8d641538cbffedf67216048de9c678ee26260eb91952';
await keyringController.addNewKeyring(KeyringType.Simple, {
privateKeys: [privateKey],
});
await keyringController.addNewKeyring(KeyringType.Simple, [privateKey]);
const appKeyAddress = await keyringController.getAppKeyAddress(
address,
'someapp.origin.io',
Expand Down Expand Up @@ -1051,9 +1040,9 @@ describe('KeyringController', () => {
};

// Add a new keyring with one account
await keyringController.addNewKeyring(KeyringType.Simple, {
privateKeys: [account.privateKey],
});
await keyringController.addNewKeyring(KeyringType.Simple, [
account.privateKey,
]);
expect(await keyringController.getAccounts()).toHaveLength(4);

// remove that account that we just added
Expand Down
18 changes: 2 additions & 16 deletions src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,22 +584,8 @@ class KeyringController extends EventEmitter {
* @param opts - The constructor options for the keyring.
* @returns The new keyring.
*/
async addNewKeyring(
type: string,
opts?: Record<string, unknown>,
): Promise<Keyring<Json>> {
let keyring: Keyring<Json>;
switch (type) {
case KeyringType.Simple:
if (!isObject(opts)) {
throw new Error('Private keys missing');
}
keyring = await this.#newKeyring(type, opts.privateKeys);
break;
default:
keyring = await this.#newKeyring(type, opts);
break;
}
async addNewKeyring(type: string, opts?: unknown): Promise<Keyring<Json>> {
const keyring = await this.#newKeyring(type, opts);

if (!keyring) {
throw new Error(KeyringControllerError.NoKeyring);
Expand Down