From 91756e6bc5a4144befb219d7b06ca4c8884752c6 Mon Sep 17 00:00:00 2001 From: Agustin Aguilar Date: Wed, 28 Jun 2023 18:21:40 +0000 Subject: [PATCH 1/3] Default to sequenceVerified = true --- packages/provider/src/provider.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/provider/src/provider.ts b/packages/provider/src/provider.ts index 2479c70a8..514a5f668 100644 --- a/packages/provider/src/provider.ts +++ b/packages/provider/src/provider.ts @@ -229,7 +229,7 @@ export class Web3Signer extends Signer implements TypedDataSigner { // signMessage matches implementation from ethers JsonRpcSigner for compatibility, but with // multi-chain support. - async signMessage(message: BytesLike, chainId?: ChainIdLike, allSigners?: boolean, sequenceVerified?: boolean): Promise { + async signMessage(message: BytesLike, chainId?: ChainIdLike, sequenceVerified: boolean = true): Promise { const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId) const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message @@ -251,8 +251,7 @@ export class Web3Signer extends Signer implements TypedDataSigner { types: Record>, message: Record, chainId?: ChainIdLike, - allSigners?: boolean, - sequenceVerified?: boolean + sequenceVerified: boolean = true ): Promise { // Populate any ENS names (in-place) // const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => { From 83e8bf7a1f6d2544fede3d44ba8f6b19722c25ca Mon Sep 17 00:00:00 2001 From: Agustin Aguilar Date: Wed, 28 Jun 2023 18:21:47 +0000 Subject: [PATCH 2/3] Pass authorizeVersion == 2 --- packages/provider/src/wallet.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/provider/src/wallet.ts b/packages/provider/src/wallet.ts index 7de77b70c..adec7eaa4 100644 --- a/packages/provider/src/wallet.ts +++ b/packages/provider/src/wallet.ts @@ -288,6 +288,11 @@ export class Wallet implements WalletProvider { } connect = async (options?: ConnectOptions): Promise => { + if (options && options?.authorizeVersion === undefined) { + // Populate default authorize version if not provided + options.authorizeVersion = 2 + } + if (options?.refresh === true) { this.disconnect() } From 9ccfc033167a672e39f59e8dd3a69231a41135e1 Mon Sep 17 00:00:00 2001 From: Agustin Aguilar Date: Wed, 28 Jun 2023 19:35:36 +0000 Subject: [PATCH 3/3] Sometimes handleConfirmWalletDeployPrompt needs to act even when sequenceVerified true --- .../src/transports/wallet-request-handler.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/provider/src/transports/wallet-request-handler.ts b/packages/provider/src/transports/wallet-request-handler.ts index 7c97ba5b1..5714b76ae 100644 --- a/packages/provider/src/transports/wallet-request-handler.ts +++ b/packages/provider/src/transports/wallet-request-handler.ts @@ -353,7 +353,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P // prompter is null, so we'll sign from here sig = await account.signMessage(prefixedMessage, chainId ?? this.defaultNetworkId) } else { - const promptResultForDeployment = request.method === 'sequence_sign' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId) + const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, request.method === 'sequence_sign', chainId) if (promptResultForDeployment) { sig = await this.prompter.promptSignMessage({ chainId: chainId, message: prefixedMessage }, this.connectOptions) } @@ -394,7 +394,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P // prompter is null, so we'll sign from here sig = await account.signTypedData(typedData.domain, typedData.types, typedData.message, chainId ?? this.defaultNetworkId) } else { - const promptResultForDeployment = request.method === 'sequence_signTypedData_v4' || await this.handleConfirmWalletDeployPrompt(this.prompter, account, chainId) + const promptResultForDeployment = await this.handleConfirmWalletDeployPrompt(this.prompter, account, request.method === 'sequence_signTypedData_v4', chainId) if (promptResultForDeployment) { sig = await this.prompter.promptSignMessage({ chainId: chainId, typedData: typedData }, this.connectOptions) } @@ -803,6 +803,7 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P private async handleConfirmWalletDeployPrompt( prompter: WalletUserPrompter, account: Account, + sequenceVerified: boolean, chainId?: number ): Promise { // check if wallet is deployed and up to date, if not, prompt user to deploy @@ -810,22 +811,30 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P if (!chainId) { return true } + + const skipsDeploy = (status: AccountStatus) => { + return status.canOnchainValidate || (status.original.version === 2 && sequenceVerified) + } + const status = await account.status(chainId) - if (status.canOnchainValidate) { + if (skipsDeploy(status)) { return true } + const promptResult = await prompter.promptConfirmWalletDeploy(chainId, this.connectOptions) + // if client returned true, check again to make sure wallet is deployed and up to date if (promptResult) { const status2 = await account.status(chainId) - const isPromptResultCorrect = isWalletUpToDate(status2) - if (!isPromptResultCorrect) { + + if (skipsDeploy(status2)) { + return true + } else { logger.error('WalletRequestHandler: result for promptConfirmWalletDeploy is not correct') return false - } else { - return true } } + return false } }