Skip to content

Commit

Permalink
Adjust prompter method interfaces to accept origin
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Nov 22, 2024
1 parent 6c1dfc3 commit 1209372
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
62 changes: 45 additions & 17 deletions packages/provider/src/transports/wallet-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
const result = await this.request({
method: message.data.method,
params: message.data.params,
chainId: message.chainId
chainId: message.chainId,
origin: message.origin,
projectAccessKey: undefined // message.projectAccessKey
})

return {
Expand All @@ -241,7 +243,13 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
}
}

async request(request: { method: string; params?: any[]; chainId?: number }): Promise<any> {
async request(request: {
method: string
params?: any[]
chainId?: number
origin?: string
projectAccessKey?: string
}): Promise<any> {
await this.getAccount()

try {
Expand Down Expand Up @@ -344,7 +352,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
message: ethers.getBytes(prefixedMessage),
eip6492: sequenceVerified
},
this.connectOptions
request.origin,
request.projectAccessKey
)
}

Expand Down Expand Up @@ -397,7 +406,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
typedData: typedData,
eip6492: sequenceVerified
},
this.connectOptions
request.origin,
request.projectAccessKey
)
}

Expand Down Expand Up @@ -431,7 +441,12 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
txnHash = txnResponse?.hash ?? ''
} else {
// prompt user to provide the response
txnHash = await this.prompter.promptSendTransaction(transactionParams, request.chainId, this.connectOptions)
txnHash = await this.prompter.promptSendTransaction(
transactionParams,
request.chainId,
request.origin,
request.projectAccessKey
)
}

if (txnHash) {
Expand Down Expand Up @@ -461,7 +476,12 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
// we will want to resolveProperties the big number values to hex strings
return await account.signTransactions(transaction, request.chainId ?? this.defaultChainId())
} else {
return await this.prompter.promptSignTransaction(transaction, request.chainId, this.connectOptions)
return await this.prompter.promptSignTransaction(
transaction,
request.chainId,
request.origin,
request.projectAccessKey
)
}
}

Expand Down Expand Up @@ -800,7 +820,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
prompter: WalletUserPrompter,
account: Account,
sequenceVerified: boolean,
chainId?: number
chainId?: number,
origin?: string
): 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
Expand All @@ -817,7 +838,7 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq
return true
}

const promptResult = await prompter.promptConfirmWalletDeploy(chainId, this.connectOptions)
const promptResult = await prompter.promptConfirmWalletDeploy(chainId, origin)

// if client returned true, check again to make sure wallet is deployed and up to date
if (promptResult) {
Expand All @@ -837,15 +858,22 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq

export interface WalletUserPrompter {
getDefaultChainId(): number

promptConnect(options?: ConnectOptions): Promise<PromptConnectDetails>
promptSignInConnect(options?: ConnectOptions): Promise<PromptConnectDetails>

promptSignMessage(message: MessageToSign, options?: ConnectOptions): Promise<string>
promptSignTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise<string>
promptSendTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise<string>
promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise<boolean>

promptConnect(connectOptions?: ConnectOptions): Promise<PromptConnectDetails>
promptSignInConnect(connectOptions?: ConnectOptions): Promise<PromptConnectDetails>
promptSignMessage(message: MessageToSign, origin?: string, projectAccessKey?: string): Promise<string>
promptSignTransaction(
txn: commons.transaction.Transactionish,
chainId?: number,
origin?: string,
projectAccessKey?: string
): Promise<string>
promptSendTransaction(
txn: commons.transaction.Transactionish,
chainId?: number,
origin?: string,
projectAccessKey?: string
): Promise<string>
promptConfirmWalletDeploy(chainId: number, origin?: string): Promise<boolean>
promptChangeNetwork(chainId: number): Promise<boolean>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class WindowMessageHandler extends BaseWalletTransport {
return
}

// Set the origin on the request
request.origin ??= event.origin

logger.debug('RECEIVED MESSAGE', request)

// Record event origin for valid init ack
Expand Down

0 comments on commit 1209372

Please sign in to comment.