From 4c908d7413758661cd7158e9aff778dd47f4b916 Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 16 Mar 2022 15:27:11 -0700 Subject: [PATCH] Better 712 errors (#13939) * Added more info for EIP-712 schema errors * Changed EthereumProviderError to EthereumRpcError * Fixed error code to not be hardcoded for signTypedData --- app/scripts/lib/typed-message-manager.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/scripts/lib/typed-message-manager.js b/app/scripts/lib/typed-message-manager.js index a0a22edb8..db65544df 100644 --- a/app/scripts/lib/typed-message-manager.js +++ b/app/scripts/lib/typed-message-manager.js @@ -1,7 +1,7 @@ import EventEmitter from 'events'; import { strict as assert } from 'assert'; import { ObservableStore } from '@metamask/obs-store'; -import { ethErrors } from 'eth-rpc-errors'; +import { EthereumRpcError, ethErrors } from 'eth-rpc-errors'; import { typedSignatureHash, TYPED_MESSAGE_SCHEMA } from 'eth-sig-util'; import log from 'loglevel'; import jsonschema from 'jsonschema'; @@ -192,11 +192,13 @@ export default class TypedMessageManager extends EventEmitter { data.primaryType in data.types, `Primary type of "${data.primaryType}" has no type definition.`, ); - assert.equal( - validation.errors.length, - 0, - 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.', - ); + if (validation.errors.length !== 0) { + throw new EthereumRpcError( + ethErrors.rpc.invalidParams, + 'Signing data must conform to EIP-712 schema. See https://git.io/fNtcx.', + validation.errors.map((v) => v.message.toString()), + ); + } let { chainId } = data.domain; if (chainId) { const activeChainId = parseInt(this._getCurrentChainId(), 16);