Skip to content

Commit

Permalink
fix: change types signatures verifyingContract validation to allow 'c…
Browse files Browse the repository at this point in the history
…osmos' as address (#334)
  • Loading branch information
jpuri authored Sep 23, 2024
1 parent 1d17a1d commit 7fbac8b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,13 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
*/
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/eth-json-rpc-middleware/issues/new
if (
verifyingContract &&
(verifyingContract as string) !== 'cosmos' &&
!isValidHexAddress(verifyingContract)
) {
throw rpcErrors.invalidInput();
}
}
Expand Down

0 comments on commit 7fbac8b

Please sign in to comment.