Skip to content

Commit 7fbac8b

Browse files
authored
fix: change types signatures verifyingContract validation to allow 'cosmos' as address (#334)
1 parent 1d17a1d commit 7fbac8b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/wallet.test.ts

+29
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

+7-1
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/eth-json-rpc-middleware/issues/new
469+
if (
470+
verifyingContract &&
471+
(verifyingContract as string) !== 'cosmos' &&
472+
!isValidHexAddress(verifyingContract)
473+
) {
468474
throw rpcErrors.invalidInput();
469475
}
470476
}

0 commit comments

Comments
 (0)