From bc086729784db9696754f8f42ba8b4e7acbdb767 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 17 Sep 2024 17:32:04 +0530 Subject: [PATCH 1/2] Change types signatures verifyingContract validation to allow 'cosmos' as address --- src/wallet.test.ts | 29 +++++++++++++++++++++++++++++ src/wallet.ts | 8 +++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/wallet.test.ts b/src/wallet.test.ts index a58efb8..27cd1fa 100644 --- a/src/wallet.test.ts +++ b/src/wallet.test.ts @@ -597,6 +597,35 @@ describe('wallet', () => { '0x68dc980608bceb5f99f691e62c32caccaee05317309015e9454eba1a14c3cd4505d1dd098b8339801239c9bcaac3c4df95569dcf307108b92f68711379be14d81c', }); }); + + it('should not throw if request is permit with verifyingContract address equal to "cosmos"', async () => { + const { engine } = createTestSetup(); + const getAccounts = async () => testAddresses.slice(); + const witnessedMsgParams: TypedMessageParams[] = []; + const processTypedMessageV4 = async (msgParams: TypedMessageParams) => { + witnessedMsgParams.push(msgParams); + // Assume testMsgSig is the expected signature result + return testMsgSig; + }; + + engine.push( + createWalletMiddleware({ getAccounts, processTypedMessageV4 }), + ); + + const payload = { + method: 'eth_signTypedData_v4', + params: [testAddresses[0], JSON.stringify(getMsgParams('cosmos'))], + }; + + const promise = pify(engine.handle).call(engine, payload); + const result = await promise; + expect(result).toStrictEqual({ + id: undefined, + jsonrpc: undefined, + result: + '0x68dc980608bceb5f99f691e62c32caccaee05317309015e9454eba1a14c3cd4505d1dd098b8339801239c9bcaac3c4df95569dcf307108b92f68711379be14d81c', + }); + }); }); describe('sign', () => { diff --git a/src/wallet.ts b/src/wallet.ts index a1e6561..6e4febc 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -464,7 +464,13 @@ WalletMiddlewareOptions): JsonRpcMiddleware { */ function validateVerifyingContract(data: string) { const { domain: { verifyingContract } = {} } = parseTypedMessage(data); - if (verifyingContract && !isValidHexAddress(verifyingContract)) { + // Explicit check for cosmos here has been added to address this issue + // https://github.com/MetaMask/metamask-extension/issues/26980 + if ( + verifyingContract && + (verifyingContract as string) !== 'cosmos' && + !isValidHexAddress(verifyingContract) + ) { throw rpcErrors.invalidInput(); } } From 67f51db2c50beb0f6cc567a979e8a3a62470de9a Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 19 Sep 2024 20:21:48 +0530 Subject: [PATCH 2/2] update --- src/wallet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet.ts b/src/wallet.ts index 6e4febc..d78e17e 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -465,7 +465,7 @@ WalletMiddlewareOptions): JsonRpcMiddleware { function validateVerifyingContract(data: string) { const { domain: { verifyingContract } = {} } = parseTypedMessage(data); // Explicit check for cosmos here has been added to address this issue - // https://github.com/MetaMask/metamask-extension/issues/26980 + // https://github.com/MetaMask/eth-json-rpc-middleware/issues/new if ( verifyingContract && (verifyingContract as string) !== 'cosmos' &&