Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const feeRecipientIfExists = _.find(
this._configs.CHAIN_ID_TO_SETTINGS[chainId].FEE_RECIPIENTS,
f => f.ADDRESS === feeRecipientAddress,
);
if (feeRecipientIfExists === undefined) {
// This error should never be hit
throw new Error(
`Unexpected error: Found feeRecipientAddress ${feeRecipientAddress} that wasn't specified in config.`,
);
}
const signature = ethUtil.ecsign(approvalHashBuff, Buffer.from(feeRecipientIfExists.PRIVATE_KEY, 'hex'));
const signatureBuffer = Buffer.concat([
ethUtil.toBuffer(signature.v),
signature.r,
signature.s,
ethUtil.toBuffer(SignatureType.EIP712),
]);
const approvalSignatureHex = ethUtil.addHexPrefix(signatureBuffer.toString('hex'));
signatures.push(approvalSignatureHex);
}
return {
signatures,
expirationTimeSeconds: approvalExpirationTimeSeconds,
};
}
} // tslint:disable:max-file-line-count
): Promise {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
assert.isETHAddressHex('signerAddress', signerAddress);
assert.doesConformToSchema('order', order, schemas.orderSchema, [schemas.hexSchema]);
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
const normalizedSignerAddress = signerAddress.toLowerCase();
const typedData = eip712Utils.createOrderTypedData(order);
try {
const signature = await web3Wrapper.signTypedDataAsync(normalizedSignerAddress, typedData);
const ecSignatureRSV = parseSignatureHexAsRSV(signature);
const signatureBuffer = Buffer.concat([
ethUtil.toBuffer(ecSignatureRSV.v),
ethUtil.toBuffer(ecSignatureRSV.r),
ethUtil.toBuffer(ecSignatureRSV.s),
ethUtil.toBuffer(SignatureType.EIP712),
]);
const signatureHex = `0x${signatureBuffer.toString('hex')}`;
return {
...order,
signature: signatureHex,
};
} catch (err) {
// Detect if Metamask to transition users to the MetamaskSubprovider
if ((provider as any).isMetaMask) {
throw new Error(TypedDataError.InvalidMetamaskSigner);
} else {
throw err;
}
}
},
/**
): Promise {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
assert.isETHAddressHex('signerAddress', signerAddress);
assert.doesConformToSchema('transaction', transaction, schemas.zeroExTransactionSchema, [schemas.hexSchema]);
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
const normalizedSignerAddress = signerAddress.toLowerCase();
const typedData = eip712Utils.createZeroExTransactionTypedData(transaction);
try {
const signature = await web3Wrapper.signTypedDataAsync(normalizedSignerAddress, typedData);
const ecSignatureRSV = parseSignatureHexAsRSV(signature);
const signatureBuffer = Buffer.concat([
ethUtil.toBuffer(ecSignatureRSV.v),
ethUtil.toBuffer(ecSignatureRSV.r),
ethUtil.toBuffer(ecSignatureRSV.s),
ethUtil.toBuffer(SignatureType.EIP712),
]);
const signatureHex = `0x${signatureBuffer.toString('hex')}`;
return {
...transaction,
signature: signatureHex,
};
} catch (err) {
// Detect if Metamask to transition users to the MetamaskSubprovider
if ((provider as any).isMetaMask) {
throw new Error(TypedDataError.InvalidMetamaskSigner);
} else {
throw err;
}
}
},
/**
private readonly _eip712SignatureAsync = async (address: string, typedData: any): Promise => {
const signature = await this.props.web3Wrapper.signTypedDataAsync(address, typedData);
const ecSignatureRSV = this._parseSignatureHexAsRSV(signature);
const signatureBuffer = Buffer.concat([
ethUtil.toBuffer(ecSignatureRSV.v),
ethUtil.toBuffer(ecSignatureRSV.r),
ethUtil.toBuffer(ecSignatureRSV.s),
ethUtil.toBuffer(SignatureType.EIP712),
]);
const signatureHex = `0x${signatureBuffer.toString('hex')}`;
return signatureHex;
};
private _parseSignatureHexAsRSV(signatureHex: string): ECSignature {