Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main with changes from v14.0.2 #340

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[14.x] fix: support ethermint's EIP712 implementation (#333)
* setting cosmos as allowed string for verifyingContract field

* fixed and linter

* readability

* Update condition to match main branch

* Remove duplicate copy of test

---------

Co-authored-by: Jyoti Puri <jyotipuri@gmail.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
  • Loading branch information
3 people authored Oct 2, 2024
commit eac3ad7d87addc46f5db70d4a155d93584628679
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
12 changes: 11 additions & 1 deletion src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,20 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
* Validates verifyingContract of typedSignMessage.
*
* @param data - The data passed in typedSign request.
* This function allows the verifyingContract to be either:
* - A valid hex address
* - The string "cosmos" (as it is hard-coded in some Cosmos ecosystem's EVM adapters)
* - An empty string
*/
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