-
-
Notifications
You must be signed in to change notification settings - Fork 268
feat: add signEip7702Authorization to KeyringController
#5301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
47935e0
276485e
5e46b8d
df91d05
3f01228
763cb3e
b5e21fd
b96c9f7
d1c2346
a50fd44
73e18fe
38f1570
a348dca
332cb55
2394767
a98db58
c4f17a1
b2b27cd
21e65a0
959414e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,10 +18,6 @@ import type { | |||||||||||||||||||||||||
| EthUserOperationPatch, | ||||||||||||||||||||||||||
| } from '@metamask/keyring-api'; | ||||||||||||||||||||||||||
| import type { EthKeyring } from '@metamask/keyring-internal-api'; | ||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||
| PersonalMessageParams, | ||||||||||||||||||||||||||
| TypedMessageParams, | ||||||||||||||||||||||||||
| } from '@metamask/message-manager'; | ||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||
| Eip1024EncryptedData, | ||||||||||||||||||||||||||
| Hex, | ||||||||||||||||||||||||||
|
|
@@ -47,6 +43,11 @@ import type { Patch } from 'immer'; | |||||||||||||||||||||||||
| import { ulid } from 'ulid'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import { KeyringControllerError } from './constants'; | ||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||
| Eip7702AuthorizationParams, | ||||||||||||||||||||||||||
| PersonalMessageParams, | ||||||||||||||||||||||||||
| TypedMessageParams, | ||||||||||||||||||||||||||
| } from './types'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const name = 'KeyringController'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -123,6 +124,11 @@ export type KeyringControllerSignMessageAction = { | |||||||||||||||||||||||||
| handler: KeyringController['signMessage']; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export type KeyringControllerSignEip7702AuthorizationAction = { | ||||||||||||||||||||||||||
| type: `${typeof name}:signEip7702Authorization`; | ||||||||||||||||||||||||||
| handler: KeyringController['signEip7702Authorization']; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export type KeyringControllerSignPersonalMessageAction = { | ||||||||||||||||||||||||||
| type: `${typeof name}:signPersonalMessage`; | ||||||||||||||||||||||||||
| handler: KeyringController['signPersonalMessage']; | ||||||||||||||||||||||||||
|
|
@@ -216,6 +222,7 @@ export type KeyringControllerQRKeyringStateChangeEvent = { | |||||||||||||||||||||||||
| export type KeyringControllerActions = | ||||||||||||||||||||||||||
| | KeyringControllerGetStateAction | ||||||||||||||||||||||||||
| | KeyringControllerSignMessageAction | ||||||||||||||||||||||||||
| | KeyringControllerSignEip7702AuthorizationAction | ||||||||||||||||||||||||||
| | KeyringControllerSignPersonalMessageAction | ||||||||||||||||||||||||||
| | KeyringControllerSignTypedMessageAction | ||||||||||||||||||||||||||
| | KeyringControllerDecryptMessageAction | ||||||||||||||||||||||||||
|
|
@@ -452,7 +459,10 @@ export function keyringBuilderFactory(KeyringConstructor: KeyringClass<Json>) { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const defaultKeyringBuilders = [ | ||||||||||||||||||||||||||
| // todo: keyring types are mismatched, this should be fixed in they keyrings themselves | ||||||||||||||||||||||||||
| // @ts-expect-error keyring types are mismatched | ||||||||||||||||||||||||||
| keyringBuilderFactory(SimpleKeyring), | ||||||||||||||||||||||||||
| // @ts-expect-error keyring types are mismatched | ||||||||||||||||||||||||||
| keyringBuilderFactory(HDKeyring), | ||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -1182,6 +1192,38 @@ export class KeyringController extends BaseController< | |||||||||||||||||||||||||
| return await keyring.signMessage(address, messageParams.data); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Signs EIP-7702 Authorization message by calling down into a specific keyring. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @param params - EIP7702AuthorizationParams object to sign. | ||||||||||||||||||||||||||
| * @returns Promise resolving to an EIP-7702 Authorization signature. | ||||||||||||||||||||||||||
| * @throws Will throw UnsupportedSignEIP7702Authorization if the keyring does not support signing EIP-7702 Authorization messages. | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| async signEip7702Authorization( | ||||||||||||||||||||||||||
| params: Eip7702AuthorizationParams, | ||||||||||||||||||||||||||
| ): Promise<string> { | ||||||||||||||||||||||||||
| const from = ethNormalize(params.from) as Hex; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const keyring = (await this.getKeyringForAccount(from)) as EthKeyring<Json>; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!keyring.signEip7702Authorization) { | ||||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||||
| KeyringControllerError.UnsupportedSignEip7702Authorization, | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const { chainId, nonce } = params; | ||||||||||||||||||||||||||
| const contractAddress = ethNormalize(params.contractAddress) as | ||||||||||||||||||||||||||
| | Hex | ||||||||||||||||||||||||||
| | undefined; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return await keyring.signEip7702Authorization(from, [ | ||||||||||||||||||||||||||
| chainId, | ||||||||||||||||||||||||||
| contractAddress as Hex, | ||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This cast is suppressing a TypeScript error about the Edit: I think I see what happened now, suggestion on this here: https://github.com/MetaMask/core/pull/5301/files#r1958425721
Comment on lines
+1216
to
+1222
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Perhaps this is what you meant to do:
Suggested change
Ideally we'd validate the response from |
||||||||||||||||||||||||||
| nonce, | ||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Signs personal message by calling down into a specific keyring. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
|
|
@@ -1795,6 +1837,11 @@ export class KeyringController extends BaseController< | |||||||||||||||||||||||||
| this.signMessage.bind(this), | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| this.messagingSystem.registerActionHandler( | ||||||||||||||||||||||||||
| `${name}:signEip7702Authorization`, | ||||||||||||||||||||||||||
| this.signEip7702Authorization.bind(this), | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| this.messagingSystem.registerActionHandler( | ||||||||||||||||||||||||||
| `${name}:signPersonalMessage`, | ||||||||||||||||||||||||||
| this.signPersonalMessage.bind(this), | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * from './KeyringController'; | ||
| export type * from './types'; |
Uh oh!
There was an error while loading. Please reload this page.