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;
23function signatureToHex(v, r, s) {
24 const ethSignature = new Uint8Array(65);
25 ethSignature.set(Buffer.from(r, 'hex'));
26 ethSignature.set(Buffer.from(s, 'hex'), 32);
29 return `0x${Buffer.from(ethSignature).toString('hex')}`;
32export const getAuthToken = async ({
38 if (walletType === WALLET_TYPES.METAMASK) {
39 return web3.eth.personal.sign(MESSAGE, wallet.address, '');
41 if (walletType === WALLET_TYPES.LEDGER) {
42 const { v, r, s } = await ledgerSignMessage(MESSAGE, walletHdPath);
43 return signatureToHex(v, r, s);
45 if (walletType === WALLET_TYPES.TREZOR) {
46 return trezorSignMessage(MESSAGE, walletHdPath);
49 const signature = signMessage(wallet.privateKey);
51 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