-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: add support to automatically upgrade account #37571
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ import { | |
| PublishHookResult, | ||
| TransactionMeta, | ||
| } from '@metamask/transaction-controller'; | ||
| import { Hex, createProjectLogger } from '@metamask/utils'; | ||
| import { Hex, add0x, createProjectLogger } from '@metamask/utils'; | ||
| import { toHex } from '@metamask/controller-utils'; | ||
| import { NetworkClientId } from '@metamask/network-controller'; | ||
| import { | ||
| BATCH_DEFAULT_MODE, | ||
| Caveat, | ||
|
|
@@ -41,6 +43,7 @@ import { | |
| submitRelayTransaction, | ||
| waitForRelayResult, | ||
| } from '../transaction-relay'; | ||
| import { stripSingleLeadingZero } from '../util'; | ||
|
|
||
| const EMPTY_HEX = '0x'; | ||
| const POLLING_INTERVAL_MS = 1000; // 1 Second | ||
|
|
@@ -58,17 +61,28 @@ export class Delegation7702PublishHook { | |
|
|
||
| #messenger: TransactionControllerInitMessenger; | ||
|
|
||
| #getNextNonce: ( | ||
| address: string, | ||
| networkClientId: NetworkClientId, | ||
| ) => Promise<Hex>; | ||
|
|
||
| constructor({ | ||
| isAtomicBatchSupported, | ||
| messenger, | ||
| getNextNonce, | ||
| }: { | ||
| isAtomicBatchSupported: ( | ||
| request: IsAtomicBatchSupportedRequest, | ||
| ) => Promise<IsAtomicBatchSupportedResult>; | ||
| messenger: TransactionControllerInitMessenger; | ||
| getNextNonce: ( | ||
| address: string, | ||
| networkClientId: NetworkClientId, | ||
| ) => Promise<Hex>; | ||
| }) { | ||
| this.#isAtomicBatchSupported = isAtomicBatchSupported; | ||
| this.#messenger = messenger; | ||
| this.#getNextNonce = getNextNonce; | ||
| } | ||
|
|
||
| getHook(): PublishHook { | ||
|
|
@@ -348,8 +362,11 @@ export class Delegation7702PublishHook { | |
| transactionMeta: TransactionMeta, | ||
| upgradeContractAddress?: Hex, | ||
| ): Promise<AuthorizationList> { | ||
| const { chainId, txParams } = transactionMeta; | ||
| const { from, nonce } = txParams; | ||
| const { chainId, txParams, networkClientId } = transactionMeta; | ||
| const { from, nonce: txNonce } = txParams; | ||
| const nextNonce = await this.#getNextNonce(from, networkClientId); | ||
|
|
||
| const nonce = txNonce ?? nextNonce; | ||
|
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. In what scenario is the
Contributor
Author
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. We don't have the |
||
|
|
||
| log('Including authorization as not upgraded'); | ||
|
|
||
|
|
@@ -393,10 +410,10 @@ export class Delegation7702PublishHook { | |
| } | ||
|
|
||
| #decodeAuthorizationSignature(signature: Hex) { | ||
| const r = signature.slice(0, 66) as Hex; | ||
| const s = `0x${signature.slice(66, 130)}` as Hex; | ||
| const r = stripSingleLeadingZero(signature.slice(0, 66)) 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. Why is this required?
Contributor
Author
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. Here, Nick mentioned that Go doesn't handle cases properly when the underlying type is an integer, and suggested using a function to strip the leading zero. It’s a bit odd, though, because we have similar logic in the Transaction Controller — it retrieves the signature from the Keyring Controller, splits it into r, s, and v, and that flow works without issues. |
||
| const s = stripSingleLeadingZero(add0x(signature.slice(66, 130))) as Hex; | ||
| const v = parseInt(signature.slice(130, 132), 16); | ||
| const yParity = v - 27 === 0 ? ('0x' as const) : ('0x1' as const); | ||
| const yParity = toHex(v - 27 === 0 ? 0 : 1); | ||
|
|
||
| return { | ||
| r, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.