1import * as secp256k1 from 'secp256k1';
3import { keccak256, WALLET_TYPES } from './wallet';
4import { ledgerSignMessage } from './ledger';
5import { trezorSignMessage } from './trezor';
7const MESSAGE = 'Bridge Authentication Token';
9function signMessage(privateKey) {
10 const { signature } = secp256k1.sign(
11 keccak256('\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE),
14 // add key recovery parameter
15 const ethSignature = new Uint8Array(65);
16 ethSignature.set(signature);
17 const v = (ethSignature[32] & 1) + 27;
23export const getAuthToken = async ({
29 if (walletType === WALLET_TYPES.METAMASK) {
30 return web3.eth.personal.sign(MESSAGE, wallet.address, '');
32 if (walletType === WALLET_TYPES.LEDGER) {
33 return ledgerSignMessage(MESSAGE, walletHdPath);
35 if (walletType === WALLET_TYPES.TREZOR) {
36 return trezorSignMessage(MESSAGE, walletHdPath);
39 const signature = signMessage(wallet.privateKey);
41 const token = `0x${Buffer.from(signature).toString('hex')}`;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list