Skip to content

Commit bc08672

Browse files
committed
Change types signatures verifyingContract validation to allow 'cosmos' as address
1 parent 1d17a1d commit bc08672

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/wallet.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,35 @@ describe('wallet', () => {
597597
'0x68dc980608bceb5f99f691e62c32caccaee05317309015e9454eba1a14c3cd4505d1dd098b8339801239c9bcaac3c4df95569dcf307108b92f68711379be14d81c',
598598
});
599599
});
600+
601+
it('should not throw if request is permit with verifyingContract address equal to "cosmos"', async () => {
602+
const { engine } = createTestSetup();
603+
const getAccounts = async () => testAddresses.slice();
604+
const witnessedMsgParams: TypedMessageParams[] = [];
605+
const processTypedMessageV4 = async (msgParams: TypedMessageParams) => {
606+
witnessedMsgParams.push(msgParams);
607+
// Assume testMsgSig is the expected signature result
608+
return testMsgSig;
609+
};
610+
611+
engine.push(
612+
createWalletMiddleware({ getAccounts, processTypedMessageV4 }),
613+
);
614+
615+
const payload = {
616+
method: 'eth_signTypedData_v4',
617+
params: [testAddresses[0], JSON.stringify(getMsgParams('cosmos'))],
618+
};
619+
620+
const promise = pify(engine.handle).call(engine, payload);
621+
const result = await promise;
622+
expect(result).toStrictEqual({
623+
id: undefined,
624+
jsonrpc: undefined,
625+
result:
626+
'0x68dc980608bceb5f99f691e62c32caccaee05317309015e9454eba1a14c3cd4505d1dd098b8339801239c9bcaac3c4df95569dcf307108b92f68711379be14d81c',
627+
});
628+
});
600629
});
601630

602631
describe('sign', () => {

src/wallet.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,13 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
464464
*/
465465
function validateVerifyingContract(data: string) {
466466
const { domain: { verifyingContract } = {} } = parseTypedMessage(data);
467-
if (verifyingContract && !isValidHexAddress(verifyingContract)) {
467+
// Explicit check for cosmos here has been added to address this issue
468+
// https://github.com/MetaMask/metamask-extension/issues/26980
469+
if (
470+
verifyingContract &&
471+
(verifyingContract as string) !== 'cosmos' &&
472+
!isValidHexAddress(verifyingContract)
473+
) {
468474
throw rpcErrors.invalidInput();
469475
}
470476
}

0 commit comments

Comments
 (0)