1 import { uint8ArrayToBase64String } from './encoding';
2 import { removeItem, setItem } from './storage';
4 export const PASSWORD_CHANGE_MESSAGE_TYPE = 'password-change';
6 const CROSS_TAB_EVENT_KEY = 'cte';
8 let id: string | undefined;
10 const generateId = () => {
11 return uint8ArrayToBase64String(crypto.getRandomValues(new Uint8Array(6)));
14 export const sendMessageToTabs = (type: string, data: any) => {
18 setItem(CROSS_TAB_EVENT_KEY, JSON.stringify({ id, type, data }));
19 removeItem(CROSS_TAB_EVENT_KEY);
22 export const getIsSelf = (otherId: string) => otherId === id;
24 export const getMessage = (event: StorageEvent) => {
25 if (event.key !== CROSS_TAB_EVENT_KEY || !event.newValue) {
29 const parsedData = JSON.parse(event.newValue);
30 if (!parsedData?.type) {
35 type: parsedData.type,
36 data: parsedData.data,