Skip to content
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
19 changes: 19 additions & 0 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,25 @@ describe('KeyringController', () => {
);
});
});

it.each([undefined, null])(
'should throw error if contract address is %s',
async (invalidContractAddress) => {
await withController(async ({ controller, initialState }) => {
const account = initialState.keyrings[0].accounts[0];
await expect(
controller.signEip7702Authorization({
from: account,
chainId,
contractAddress: invalidContractAddress as unknown as string,
nonce,
}),
).rejects.toThrow(
KeyringControllerError.MissingEip7702AuthorizationContractAddress,
);
});
},
);
});

describe('when the keyring for the given address does not support signEip7702Authorization', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,15 @@ export class KeyringController extends BaseController<
| Hex
| undefined;

if (contractAddress === undefined) {
throw new Error(
KeyringControllerError.MissingEip7702AuthorizationContractAddress,
);
}

return await keyring.signEip7702Authorization(from, [
chainId,
contractAddress as Hex,
contractAddress,
nonce,
]);
}
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-controller/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum KeyringControllerError {
UnsupportedPatchUserOperation = 'KeyringController - The keyring for the current address does not support the method patchUserOperation.',
UnsupportedSignUserOperation = 'KeyringController - The keyring for the current address does not support the method signUserOperation.',
UnsupportedVerifySeedPhrase = 'KeyringController - The keyring does not support the method verifySeedPhrase.',
MissingEip7702AuthorizationContractAddress = 'KeyringController - The EIP-7702 Authorization is invalid. No contract address provided.',
NoAccountOnKeychain = "KeyringController - The keychain doesn't have accounts.",
ControllerLocked = 'KeyringController - The operation cannot be completed while the controller is locked.',
MissingCredentials = 'KeyringController - Cannot persist vault without password and encryption key',
Expand Down
Loading