@@ -1,3 +1,4 @@
1+import { crypto } from 'bitcoinjs-lib';
1import { ecdsaSign } from 'secp256k1';
2import { ecdsaSign } from 'secp256k1';
2import Web3 from 'web3';
3import Web3 from 'web3';
3import { hexToBytes } from 'web3-utils';
4import { hexToBytes } from 'web3-utils';
@@ -12,9 +13,11 @@ import { keccak256 } from 'ethereumjs-util';
13const MESSAGE = 'Bridge Authentication Token';
14const MESSAGE = 'Bridge Authentication Token';
15−function signMessage(privateKey: Buffer) {
16+function signMessage(privateKey: Buffer, useLegacyTokenSigning = false) {
16 const msg = '\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE;
17 const msg = '\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE;
18+ const hashed = useLegacyTokenSigning
19+ ? crypto.sha256(Buffer.from(msg))
17− const hashed = keccak256(Buffer.from(msg));
20+ : keccak256(Buffer.from(msg));
18 const { signature } = ecdsaSign(Buffer.from(hashed), privateKey);
21 const { signature } = ecdsaSign(Buffer.from(hashed), privateKey);
20 // add key recovery parameter
23 // add key recovery parameter
@@ -60,6 +63,7 @@ type WalletConnectAuthTokenArgs = {
60type DefaultAuthTokenArgs = {
63type DefaultAuthTokenArgs = {
61 wallet: BridgeWallet;
64 wallet: BridgeWallet;
62 walletType?: symbol;
65 walletType?: symbol;
66+ useLegacyTokenSigning?: boolean;
65type GetAuthTokenArgs =
69type GetAuthTokenArgs =
@@ -100,8 +104,11 @@ const getWalletConnectAuthToken = ({
100 return connector.signPersonalMessage([MESSAGE, address]);
104 return connector.signPersonalMessage([MESSAGE, address]);
103−const getDefaultAuthToken = ({ wallet }: DefaultAuthTokenArgs) => {
107+const getDefaultAuthToken = ({
109+ useLegacyTokenSigning = false,
110+}: DefaultAuthTokenArgs) => {
104− const signature = signMessage(wallet.privateKey!);
111+ const signature = signMessage(wallet.privateKey!, useLegacyTokenSigning);
106 const token = `0x${Buffer.from(signature).toString('hex')}`;
113 const token = `0x${Buffer.from(signature).toString('hex')}`;