Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert.doesNotThrow(() => {
sigUtil.typedSignatureHash(params.data)
}, 'Expected EIP712 typed data')
break
case 'V3':
case 'V4':
let data
assert.equal(typeof params, 'object', 'Params should be an object.')
assert.ok('data' in params, 'Params must include a data field.')
assert.ok('from' in params, 'Params must include a from field.')
assert.equal(typeof params.from, 'string', 'From field must be a string.')
assert.equal(typeof params.data, 'string', 'Data must be passed as a valid JSON string.')
assert.doesNotThrow(() => {
data = JSON.parse(params.data)
}, 'Data must be passed as a valid JSON string.')
const validation = jsonschema.validate(data, sigUtil.TYPED_MESSAGE_SCHEMA)
assert.ok(data.primaryType in data.types, `Primary type of "${data.primaryType}" has no type definition.`)
assert.equal(validation.errors.length, 0, 'Data must conform to EIP-712 schema. See https://git.io/fNtcx.')
const chainId = data.domain.chainId
const activeChainId = parseInt(this.networkController.getNetworkState())
chainId && assert.equal(chainId, activeChainId, `Provided chainId (${chainId}) must match the active chainId (${activeChainId})`)
break
default:
assert.fail(`Unknown params.version ${params.version}`)
}
}
export function validateTypedSignMessageDataV3(messageData: TypedMessageParams) {
if (!messageData.from || typeof messageData.from !== 'string' || !isValidAddress(messageData.from)) {
throw new Error(`Invalid "from" address: ${messageData.from} must be a valid string.`);
}
if (!messageData.data || typeof messageData.data !== 'string') {
throw new Error(`Invalid message "data": ${messageData.data} must be a valid array.`);
}
let data;
try {
data = JSON.parse(messageData.data);
} catch (e) {
throw new Error('Data must be passed as a valid JSON string.');
}
const validation = jsonschema.validate(data, sigUtil.TYPED_MESSAGE_SCHEMA);
if (validation.errors.length > 0) {
throw new Error('Data must conform to EIP-712 schema. See https://git.io/fNtcx.');
}
}