aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-10-08 08:13:04 +0800
committerJacob Evans <jacob@dekz.net>2018-10-08 08:13:04 +0800
commite1236a484623e9d2caab823c476175cb255ae816 (patch)
tree6d6faae42d2825efa9330f417432303de1d82ab0 /packages
parent75d274f330dc0c18577e764ca77ffb36d5a3f27e (diff)
downloaddexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar.gz
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar.bz2
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar.lz
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar.xz
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.tar.zst
dexon-sol-tools-e1236a484623e9d2caab823c476175cb255ae816.zip
Detect MM on signature validation failure.
Report a developer friendly error in this event to educate them on the compatability wrapper MetamaskSubprovider
Diffstat (limited to 'packages')
-rw-r--r--packages/order-utils/src/signature_utils.ts52
1 files changed, 28 insertions, 24 deletions
diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts
index 8c92b87dd..e518b29a0 100644
--- a/packages/order-utils/src/signature_utils.ts
+++ b/packages/order-utils/src/signature_utils.ts
@@ -228,25 +228,30 @@ export const signatureUtils = {
assert.isETHAddressHex('signerAddress', signerAddress);
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
- // Detect if Metamask to transition users to the MetamaskSubprovider
- if ((provider as any).isMetaMask) {
- throw new Error('Unsupported Provider, please use MetamaskSubprovider.');
- }
const normalizedSignerAddress = signerAddress.toLowerCase();
const typedData = eip712Utils.createOrderTypedData(order);
- 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,
- };
+ 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(`Unsupported Provider, please use MetamaskSubprovider: ${err.message}`);
+ } else {
+ throw err;
+ }
+ }
},
/**
* Signs a hash and returns its elliptic curve signature and signature type.
@@ -262,11 +267,6 @@ export const signatureUtils = {
const web3Wrapper = new Web3Wrapper(provider);
await assert.isSenderAddressAsync('signerAddress', signerAddress, web3Wrapper);
const normalizedSignerAddress = signerAddress.toLowerCase();
- // Detect if Metamask to transition users to the MetamaskSubprovider
- if ((provider as any).isMetaMask) {
- throw new Error('Unsupported Provider, please use MetamaskSubprovider.');
- }
-
const signature = await web3Wrapper.signMessageAsync(normalizedSignerAddress, msgHash);
const prefixedMsgHashHex = signatureUtils.addSignedMessagePrefix(msgHash);
@@ -301,8 +301,12 @@ export const signatureUtils = {
return convertedSignatureHex;
}
}
-
- throw new Error(OrderError.InvalidSignature);
+ // Detect if Metamask to transition users to the MetamaskSubprovider
+ if ((provider as any).isMetaMask) {
+ throw new Error('Unsupported Provider, please use MetamaskSubprovider.');
+ } else {
+ throw new Error(OrderError.InvalidSignature);
+ }
},
/**
* Combines ECSignature with V,R,S and the EthSign signature type for use in 0x protocol