From 12093725023007f81f5725ab25af3b00da728fb9 Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Fri, 22 Nov 2024 13:48:56 -0500 Subject: [PATCH] Adjust prompter method interfaces to accept origin --- .../src/transports/wallet-request-handler.ts | 62 ++++++++++++++----- .../window-message-handler.ts | 3 + 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/packages/provider/src/transports/wallet-request-handler.ts b/packages/provider/src/transports/wallet-request-handler.ts index 6b18e9e27..fb0eb7719 100644 --- a/packages/provider/src/transports/wallet-request-handler.ts +++ b/packages/provider/src/transports/wallet-request-handler.ts @@ -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 { @@ -241,7 +243,13 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq } } - async request(request: { method: string; params?: any[]; chainId?: number }): Promise { + async request(request: { + method: string + params?: any[] + chainId?: number + origin?: string + projectAccessKey?: string + }): Promise { await this.getAccount() try { @@ -344,7 +352,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq message: ethers.getBytes(prefixedMessage), eip6492: sequenceVerified }, - this.connectOptions + request.origin, + request.projectAccessKey ) } @@ -397,7 +406,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq typedData: typedData, eip6492: sequenceVerified }, - this.connectOptions + request.origin, + request.projectAccessKey ) } @@ -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) { @@ -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 + ) } } @@ -800,7 +820,8 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq prompter: WalletUserPrompter, account: Account, sequenceVerified: boolean, - chainId?: number + chainId?: number, + origin?: string ): Promise { // 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 @@ -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) { @@ -837,15 +858,22 @@ export class WalletRequestHandler implements EIP1193Provider, ProviderMessageReq export interface WalletUserPrompter { getDefaultChainId(): number - - promptConnect(options?: ConnectOptions): Promise - promptSignInConnect(options?: ConnectOptions): Promise - - promptSignMessage(message: MessageToSign, options?: ConnectOptions): Promise - promptSignTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise - promptSendTransaction(txn: commons.transaction.Transactionish, chainId?: number, options?: ConnectOptions): Promise - promptConfirmWalletDeploy(chainId: number, options?: ConnectOptions): Promise - + promptConnect(connectOptions?: ConnectOptions): Promise + promptSignInConnect(connectOptions?: ConnectOptions): Promise + promptSignMessage(message: MessageToSign, origin?: string, projectAccessKey?: string): Promise + promptSignTransaction( + txn: commons.transaction.Transactionish, + chainId?: number, + origin?: string, + projectAccessKey?: string + ): Promise + promptSendTransaction( + txn: commons.transaction.Transactionish, + chainId?: number, + origin?: string, + projectAccessKey?: string + ): Promise + promptConfirmWalletDeploy(chainId: number, origin?: string): Promise promptChangeNetwork(chainId: number): Promise } diff --git a/packages/provider/src/transports/window-transport/window-message-handler.ts b/packages/provider/src/transports/window-transport/window-message-handler.ts index 87a279627..dd7bf38f9 100644 --- a/packages/provider/src/transports/window-transport/window-message-handler.ts +++ b/packages/provider/src/transports/window-transport/window-message-handler.ts @@ -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