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
5 changes: 2 additions & 3 deletions packages/provider/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
async signMessage(message: BytesLike, chainId?: ChainIdLike, sequenceVerified: boolean = true): Promise<string> {
const provider = await this.getSender(maybeChainId(chainId) || this.defaultChainId)

const data = typeof message === 'string' ? ethers.utils.toUtf8Bytes(message) : message
Expand All @@ -251,8 +251,7 @@ export class Web3Signer extends Signer implements TypedDataSigner {
types: Record<string, Array<TypedDataField>>,
message: Record<string, any>,
chainId?: ChainIdLike,
allSigners?: boolean,
sequenceVerified?: boolean
sequenceVerified: boolean = true
): Promise<string> {
// Populate any ENS names (in-place)
// const populated = await ethers.utils._TypedDataEncoder.resolveNames(domain, types, message, (name: string) => {
Expand Down
23 changes: 16 additions & 7 deletions packages/provider/src/transports/wallet-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -803,29 +803,38 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
private async handleConfirmWalletDeployPrompt(
prompter: WalletUserPrompter,
account: Account,
sequenceVerified: boolean,
chainId?: number
): Promise<boolean> {
// check if wallet is deployed and up to date, if not, prompt user to deploy
// if no chainId is provided, we'll assume the wallet is auth chain wallet and is up to date
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
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/provider/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ export class Wallet implements WalletProvider {
}

connect = async (options?: ConnectOptions): Promise<ConnectDetails> => {
if (options && options?.authorizeVersion === undefined) {
// Populate default authorize version if not provided
options.authorizeVersion = 2
}

if (options?.refresh === true) {
this.disconnect()
}
Expand Down