/**
 * @fileOverview exposes only required apis to rendering process to minimize attack surface
 */

var { contextBridge, ipcRenderer } = require("electron");

const filter = event => {
  if (
    !/^(lnd)|(unlock)|(pyFace)|(log)|(locale)|(open-url)[a-zA-Z_-]{0,20}$/.test(event)
  ) {
    throw new Error(`Invalid IPC: ${event}`);
  }
  return event;
};

wipcRenderer = {
  send: (event, data) => {
    _ipcRenderer.send(filter(event), data);
  },
  on: (event, callback) => {
    _ipcRenderer.on(filter(event), callback);
  },
  once: (event, callback) => {
    _ipcRenderer.once(filter(event), callback);
  },
};


let iipcRenderer = Object.assign(wipcRenderer, ipcRenderer);
console.log(ipcRenderer);



contextBridge.exposeInMainWorld(
    "electron",
    {
        ipcRenderer: iipcRenderer
    }
);

const _ipcRenderer = ipcRenderer;

