on master help sign in
lib: fix metamask wonkiness with personal_sign
0f1adfepkova
src/lib/authToken.ts+4−3
@@ -1,7 +1,7 @@
1import { crypto } from 'bitcoinjs-lib';
1import { crypto } from 'bitcoinjs-lib';
2import { ecdsaSign } from 'secp256k1';
2import { ecdsaSign } from 'secp256k1';
3import Web3 from 'web3';
3import Web3 from 'web3';
4−import { hexToBytes } from 'web3-utils';
4+import { hexToBytes, utf8ToHex } from 'web3-utils';
5import { hashPersonalMessage } from '@ethereumjs/util';
5import { hashPersonalMessage } from '@ethereumjs/util';
6import { WALLET_TYPES } from './constants';
6import { WALLET_TYPES } from './constants';
7import BridgeWallet from './types/BridgeWallet';
7import BridgeWallet from './types/BridgeWallet';
@@ -76,10 +76,11 @@ const getMetamaskAuthToken = ({ address, web3 }: MetamaskAuthTokenArgs) => {
76 // but web3.eth.personal.sign hits it semi-reliably?
76 // but web3.eth.personal.sign hits it semi-reliably?
77 // no idea what's going on, we should figure it out,
77 // no idea what's going on, we should figure it out,
78 // but we apply this bandaid to hopefully stop the bleeding.
78 // but we apply this bandaid to hopefully stop the bleeding.
79+ //NOTE personal_sign expects hex-encoded data; signing the hex of
80+ // MESSAGE yields the same signature as the other wallet types
79 return window.ethereum.request({
81 return window.ethereum.request({
80 method: 'personal_sign',
82 method: 'personal_sign',
81− params: [MESSAGE, address],
83+ params: [utf8ToHex(MESSAGE), address],
82− from: address,
83 });
84 });
84 } else {
85 } else {
85 return web3.eth.personal.sign(MESSAGE, address, '');
86 return web3.eth.personal.sign(MESSAGE, address, '');