1import * as secp256k1 from 'secp256k1';
3import { keccak256, WALLET_TYPES } from './wallet';
4import { ledgerSignMessage } from './ledger';
6const MESSAGE = 'Bridge Authentication Token';
8function signMessage(privateKey) {
9 const { signature } = secp256k1.sign(
10 keccak256('\x19Ethereum Signed Message:\n' + MESSAGE.length + MESSAGE),
13 // add key recovery parameter
14 const ethSignature = new Uint8Array(65);
15 ethSignature.set(signature);
16 const v = (ethSignature[32] & 1) + 27;
22function signatureToHex(v, r, s) {
23 const ethSignature = new Uint8Array(65);
24 ethSignature.set(Buffer.from(r, 'hex'));
25 ethSignature.set(Buffer.from(s, 'hex'), 32);
28 return `0x${Buffer.from(ethSignature).toString('hex')}`;
31export const getAuthToken = async ({
37 if (walletType === WALLET_TYPES.METAMASK) {
38 return web3.eth.personal.sign(MESSAGE, wallet.address, '');
40 if (walletType === WALLET_TYPES.LEDGER) {
41 const { v, r, s } = await ledgerSignMessage(MESSAGE, walletHdPath);
42 return signatureToHex(v, r, s);
45 const signature = signMessage(wallet.privateKey);
47 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