-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.ts
34 lines (28 loc) · 1.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { CONTENT_PORT_NAME, createChannel, createPortTransport, serializeMessage } from '../messages';
import { deriveEthereumAccount, deriveSolanaAccount, generateMnemonic } from './wallet';
chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
const mnemonic = generateMnemonic();
chrome.storage.local.set({ mnemonic });
}
});
chrome.runtime.onConnect.addListener((port) => {
if (port.name === CONTENT_PORT_NAME) {
const transport = createPortTransport(port);
const channel = createChannel(transport);
const unsubscribe = channel.onMessage('connect', async (_params, sendResponse) => {
const { mnemonic } = await chrome.storage.local.get('mnemonic');
const ethereumAccount = deriveEthereumAccount(mnemonic);
const solanaAccount = deriveSolanaAccount(mnemonic);
// TODO: Open popup and allow user to select accounts.
const response = [
{ chain: 'ethereum', publicKey: serializeMessage(ethereumAccount.publicKey) },
{ chain: 'solana', publicKey: serializeMessage(solanaAccount.publicKey) },
];
sendResponse(response);
});
port.onDisconnect.addListener(() => {
unsubscribe();
});
}
});