/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/@aladas-org/cryptocalc@0.5.34/www/js/_main/electron_main.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";const MAIN_WINDOW_WIDTH=1040,MAIN_WINDOW_HEIGHT=690,{app:app,Menu:Menu,BrowserWindow:BrowserWindow,ipcMain:ipcMain,shell:shell,remote:remote,dialog:dialog}=require("electron");require("v8-compile-cache");const os=require("os"),{exec:exec}=require("child_process"),WINDOWS="win32",LINUX="linux",FREE_BSD="freebsd",OPEN_BSD="openbsd",fs=require("fs"),path=require("path"),{v4:uuidv4}=require("uuid"),checkInternetConnected=require("check-internet-connected"),PasswordGenerator=require("generate-password"),{_CYAN_:_CYAN_,_RED_:_RED_,_PURPLE_:_PURPLE_,_YELLOW_:_YELLOW_,_END_:_END_}=require("../util/color/color_console_codes.js"),{pretty_func_header_log:pretty_func_header_log,pretty_log:pretty_log}=require("../util/log/log_utils.js"),{Skribi:Skribi}=require("../util/log/skribi.js"),{APP_VERSION:APP_VERSION,PROGRAM:PROGRAM,ELECTRON_LAUNCHER:ELECTRON_LAUNCHER,EXE_LAUNCHER:EXE_LAUNCHER,OUTPUT_DIR_PATH:OUTPUT_DIR_PATH,INVALID_OUTPUT_DIR_PATH:INVALID_OUTPUT_DIR_PATH,SELECT_DIRECTORY_PATH_MODE:SELECT_DIRECTORY_PATH_MODE,SELECT_FILE_PATH_MODE:SELECT_FILE_PATH_MODE,WITS_PATH:WITS_PATH,PATH:PATH,ARGS:ARGS,BLOCKCHAIN:BLOCKCHAIN,BIP39_PASSPHRASE:BIP39_PASSPHRASE,BIP32_PROTOCOL:BIP32_PROTOCOL,ACCOUNT:ACCOUNT,ADDRESS_INDEX:ADDRESS_INDEX,TO_RAW_TEXT:TO_RAW_TEXT,TO_BASE64:TO_BASE64,TO_BASE58:TO_BASE58,TO_MNEMONICS:TO_MNEMONICS,TO_BINARY:TO_BINARY,FROM_RAW_TEXT:FROM_RAW_TEXT,FROM_BASE64:FROM_BASE64,FROM_BASE58:FROM_BASE58,FROM_MNEMONICS:FROM_MNEMONICS,FROM_BINARY:FROM_BINARY}=require("../const_keywords.js"),{CRYPTO_NET:CRYPTO_NET}=require("../crypto/const_wallet.js"),{CMD_OPEN_WALLET:CMD_OPEN_WALLET,VIEW_TOGGLE_DEVTOOLS:VIEW_TOGGLE_DEVTOOLS,TOOLS_OPTIONS:TOOLS_OPTIONS,TOOLS_DATABASE_MANAGEMENT:TOOLS_DATABASE_MANAGEMENT,TOOLS_BIP38_ENCRYPTER_DECRYTER:TOOLS_BIP38_ENCRYPTER_DECRYTER,TOOLS_SECRET_PHRASE_TRANSLATOR:TOOLS_SECRET_PHRASE_TRANSLATOR,ToMain_RQ_QUIT_APP:ToMain_RQ_QUIT_APP,ToMain_RQ_LOG_2_MAIN:ToMain_RQ_LOG_2_MAIN,ToMain_RQ_LOG_2_MAIN_SYNC:ToMain_RQ_LOG_2_MAIN_SYNC,ToMain_RQ_GET_APP_PATH:ToMain_RQ_GET_APP_PATH,ToMain_RQ_EXEC_CMD:ToMain_RQ_EXEC_CMD,ToMain_RQ_SET_WINDOW_TITLE:ToMain_RQ_SET_WINDOW_TITLE,ToMain_RQ_TOGGLE_DEBUG_PANEL:ToMain_RQ_TOGGLE_DEBUG_PANEL,ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG:ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG,ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE:ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE,ToMain_RQ_NEW_WALLET_INFO:ToMain_RQ_NEW_WALLET_INFO,ToMain_RQ_OPEN_WALLET_INFO:ToMain_RQ_OPEN_WALLET_INFO,ToMain_RQ_SAVE_WALLET_INFO:ToMain_RQ_SAVE_WALLET_INFO,ToMain_RQ_OPEN_URL:ToMain_RQ_OPEN_URL,ToMain_RQ_SHOW_OUTPUT_FOLDER_IN_EXPLORER:ToMain_RQ_SHOW_OUTPUT_FOLDER_IN_EXPLORER,ToMain_RQ_LOAD_IMG_FROM_FILE:ToMain_RQ_LOAD_IMG_FROM_FILE,ToMain_RQ_DRAW_RND_CRYPTO_LOGO:ToMain_RQ_DRAW_RND_CRYPTO_LOGO,ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO:ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO,ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO_CUSTOM:ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO_CUSTOM,ToMain_RQ_MNEMONICS_TO_HD_WALLET_INFO:ToMain_RQ_MNEMONICS_TO_HD_WALLET_INFO,ToMain_RQ_GET_SIMPLE_WALLET:ToMain_RQ_GET_SIMPLE_WALLET,ToMain_RQ_ENTROPY_TO_MNEMONICS:ToMain_RQ_ENTROPY_TO_MNEMONICS,ToMain_RQ_ENTROPY_TO_CHECKSUM:ToMain_RQ_ENTROPY_TO_CHECKSUM,ToMain_RQ_ENTROPY_SRC_TO_ENTROPY:ToMain_RQ_ENTROPY_SRC_TO_ENTROPY,ToMain_RQ_MNEMONICS_AS_4LETTER:ToMain_RQ_MNEMONICS_AS_4LETTER,ToMain_RQ_MNEMONICS_AS_TWO_PARTS:ToMain_RQ_MNEMONICS_AS_TWO_PARTS,ToMain_RQ_GET_UUID:ToMain_RQ_GET_UUID,ToMain_RQ_GET_L10N_KEYPAIRS:ToMain_RQ_GET_L10N_KEYPAIRS,ToMain_RQ_GET_L10N_MSG:ToMain_RQ_GET_L10N_MSG,ToMain_RQ_SET_MENU_ITEM_STATE:ToMain_RQ_SET_MENU_ITEM_STATE,ToMain_RQ_CHECK_MNEMONICS:ToMain_RQ_CHECK_MNEMONICS,ToMain_RQ_WORD_INDEX_TO_MNEMONIC:ToMain_RQ_WORD_INDEX_TO_MNEMONIC,ToMain_RQ_WORD_INDEXES_TO_MNEMONICS:ToMain_RQ_WORD_INDEXES_TO_MNEMONICS,ToMain_RQ_MNEMONIC_TO_WORD_INDEX:ToMain_RQ_MNEMONIC_TO_WORD_INDEX,ToMain_RQ_MNEMONICS_TO_WORD_INDEXES:ToMain_RQ_MNEMONICS_TO_WORD_INDEXES,ToMain_RQ_GUESS_MNEMONICS_LANG:ToMain_RQ_GUESS_MNEMONICS_LANG,ToMain_RQ_GET_OPTIONS:ToMain_RQ_GET_OPTIONS,ToMain_RQ_SAVE_OPTIONS:ToMain_RQ_SAVE_OPTIONS,ToMain_RQ_RESET_OPTIONS:ToMain_RQ_RESET_OPTIONS,ToMain_RQ_UPDATE_OPTIONS:ToMain_RQ_UPDATE_OPTIONS,ToMain_RQ_GET_FORTUNE_COOKIE:ToMain_RQ_GET_FORTUNE_COOKIE,ToMain_RQ_GENERATE_ENTROPY:ToMain_RQ_GENERATE_ENTROPY,ToMain_RQ_GENERATE_PASSWORD:ToMain_RQ_GENERATE_PASSWORD,ToMain_RQ_FROM_HEX_CONVERSIONS:ToMain_RQ_FROM_HEX_CONVERSIONS,ToMain_RQ_TO_HEX_CONVERSIONS:ToMain_RQ_TO_HEX_CONVERSIONS,ToMain_RQ_GET_HD_WALLET:ToMain_RQ_GET_HD_WALLET,ToMain_RQ_BIP85_DERIVE_BIP39:ToMain_RQ_BIP85_DERIVE_BIP39,ToMain_RQ_BIP38_ENCRYPT:ToMain_RQ_BIP38_ENCRYPT,ToMain_RQ_BIP38_DECRYPT:ToMain_RQ_BIP38_DECRYPT,ToMain_RQ_GET_PASSWORD_STRENGTH:ToMain_RQ_GET_PASSWORD_STRENGTH,FromMain_DID_FINISH_LOAD:FromMain_DID_FINISH_LOAD,FromMain_EXEC_CMD:FromMain_EXEC_CMD,FromMain_FILE_NEW:FromMain_FILE_NEW,FromMain_FILE_OPEN:FromMain_FILE_OPEN,FromMain_FILE_SAVE:FromMain_FILE_SAVE,FromMain_HELP_ABOUT:FromMain_HELP_ABOUT,FromMain_TOOLS_OPTIONS_DIALOG:FromMain_TOOLS_OPTIONS_DIALOG,FromMain_TOOLS_DB_MANAGEMENT_DIALOG:FromMain_TOOLS_DB_MANAGEMENT_DIALOG,FromMain_TOOLS_BIP38_ENCRYPT_DECRYPT_DIALOG:FromMain_TOOLS_BIP38_ENCRYPT_DECRYPT_DIALOG,FromMain_TOOLS_SECRET_PHRASE_TRANSLATOR_DIALOG:FromMain_TOOLS_SECRET_PHRASE_TRANSLATOR_DIALOG,FromMain_TOOLS_ENTROPY_CONVERTER_DIALOG:FromMain_TOOLS_ENTROPY_CONVERTER_DIALOG,FromMain_UPDATE_OPTIONS:FromMain_UPDATE_OPTIONS,FromMain_SEND_IMG_URL:FromMain_SEND_IMG_URL,FromMain_SET_FORTUNE_COOKIE:FromMain_SET_FORTUNE_COOKIE,FromMain_SET_VARIABLE:FromMain_SET_VARIABLE,FromMain_INTERNET_CONNECTED:FromMain_INTERNET_CONNECTED}=require("../const_events.js"),{ENTROPY_SOURCE_IMG_ID:ENTROPY_SOURCE_IMG_ID,ENTROPY_CONVERTER_DIALOG_ID:ENTROPY_CONVERTER_DIALOG_ID}=require("../view/const_gui.js"),{DEFAULT_OPTIONS:DEFAULT_OPTIONS}=require("../crypto/const_default_options.js"),{getShortenedString:getShortenedString}=require("../util/values/string_utils.js"),{FileUtils:FileUtils}=require("../util/system/file_utils.js"),{Bip39Utils:Bip39Utils}=require("../crypto/bip39_utils.js"),{Bip38Utils:Bip38Utils}=require("../crypto/bip38_utils.js"),{Bip85Utils:Bip85Utils}=require("../crypto/bip85_utils.js"),{PasswordStrengthEvaluator:PasswordStrengthEvaluator}=require("../crypto/password_strength_evaluator.js"),{isHexString:isHexString,hexToB64:hexToB64,b64ToHex:b64ToHex,hexToBinary:hexToBinary,binaryToHex:binaryToHex,getRandomInt:getRandomInt,getRandomHexValue:getRandomHexValue}=require("../crypto/hex_utils.js"),{hexToB58:hexToB58,b58ToHex:b58ToHex}=require("../crypto/base58_utils.js"),{getFortuneCookie:getFortuneCookie}=require("../util/fortune/fortune.js"),{L10nUtils:L10nUtils}=require("../L10n/L10n_utils.js"),{Bip32Utils:Bip32Utils}=require("../crypto/HDWallet/bip32_utils.js"),{HDWallet:HDWallet}=require("../crypto/HDWallet/hd_wallet.js"),{SimpleWallet:SimpleWallet}=require("../crypto/SimpleWallet/simple_wallet.js"),{MainModel:MainModel}=require("../model/main_model.js"),{SqLiteUtils:SqLiteUtils}=require("./db/sqlite_utils.js"),DEFAULT_APP_CONFIG={ToFile:!0},gotTheLock=app.requestSingleInstanceLock(),error_handler=_=>{if(_)return Skribi.log("error: "+_);Skribi.log("saving file... "+filename)};class ElectronMain{static#_=Symbol();static#e=new ElectronMain(this.#_);static#n=0;static GetInstance(){if(null==ElectronMain.#e){if(this.#e=new ElectronMain(this.#_),this.#n>0)throw new TypeError("'ElectronMain' constructor called more than once");this.#n++}return ElectronMain.#e}constructor(_){if(_!==ElectronMain.#_)throw new TypeError("'ElectronMain' constructor is private");this.cryptowallet_version="x.x.x",this.app_config=DEFAULT_APP_CONFIG,this.cmd_line={},this.cmd_line[PROGRAM]=ELECTRON_LAUNCHER,this.cmd_line[PATH]=".",this.cmd_line[ARGS]="",this.DidFinishLoad_FiredCount=0,this.Show_DebugPanel=!1,this.MainWindow=void 0,this.Options={},this.SupportedBlockchains={},this.FirstImageAsEntropySource=!0,this.output_path=""}createBrowserWindow(_){new BrowserWindow({height:900,width:1200}).loadURL(_)}getMainWindow(){return this.MainWindow}isLaunchedFromExe(){return this.cmd_line[PROGRAM]==EXE_LAUNCHER}getCmdLineArgs(){let _=process.argv.length;return _>0&&(this.cmd_line[PROGRAM]=path.basename(process.argv[0])),_>1&&(this.cmd_line[PATH]=process.argv[1]),_>2&&(this.cmd_line[ARGS]=process.argv[2]),"nb_args: "+_+PROGRAM+": "+this.cmd_line[PROGRAM]+PATH+": "+this.cmd_line[PATH]+ARGS+": "+this.cmd_line[ARGS]}getMenuTemplate(){return[{label:L10nUtils.GetLocalizedMsg("File"),submenu:[{label:L10nUtils.GetLocalizedMsg("New"),async click(){await ElectronMain.GetInstance().doFileNew()}},{label:L10nUtils.GetLocalizedMsg("Open"),async click(){await ElectronMain.GetInstance().doFileOpen()}},{label:L10nUtils.GetLocalizedMsg("Save"),click(){ElectronMain.GetInstance().doFileSave()},id:"file_save_menu_item_id"},{label:L10nUtils.GetLocalizedMsg("SaveAs"),click(){ElectronMain.GetInstance().doFileSaveAs()},id:"file_save_as_menu_item_id"},{label:L10nUtils.GetLocalizedMsg("Quit"),click(){app.quit()}}]},{label:L10nUtils.GetLocalizedMsg("View"),submenu:[{label:L10nUtils.GetLocalizedMsg("ToggleDebug"),type:"checkbox",click(){pretty_func_header_log("[Electron]",VIEW_TOGGLE_DEVTOOLS),ElectronMain.GetInstance().toggleDebugPanel()}}]},{label:L10nUtils.GetLocalizedMsg("Tools"),submenu:[{label:"Options...",click(){pretty_func_header_log("[Electron]",TOOLS_OPTIONS),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_TOOLS_OPTIONS_DIALOG,ElectronMain.GetInstance().Options])}},{label:L10nUtils.GetLocalizedMsg("DatabaseManagementTool"),click(){pretty_func_header_log("[Electron]",TOOLS_DATABASE_MANAGEMENT),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_TOOLS_DB_MANAGEMENT_DIALOG,SqLiteUtils.This.appFolderPath])}},{label:L10nUtils.GetLocalizedMsg("SecretPhraseTranslatorTool"),click(){pretty_func_header_log("[Electron]",TOOLS_SECRET_PHRASE_TRANSLATOR),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_TOOLS_SECRET_PHRASE_TRANSLATOR_DIALOG,ElectronMain.GetInstance().Options])}},{label:L10nUtils.GetLocalizedMsg("EntropyConverterTool"),click(){pretty_func_header_log("[Electron]",ENTROPY_CONVERTER_DIALOG_ID),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_TOOLS_ENTROPY_CONVERTER_DIALOG,ElectronMain.GetInstance().Options])}},{label:L10nUtils.GetLocalizedMsg("Bip38EncryptDecryptTool"),click(){pretty_func_header_log("[Electron]",TOOLS_BIP38_ENCRYPTER_DECRYTER),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_TOOLS_BIP38_ENCRYPT_DECRYPT_DIALOG,ElectronMain.GetInstance().Options])}}]},{label:L10nUtils.GetLocalizedMsg("Help"),submenu:[{label:"Setup guide and User's Manual",click(){ElectronMain.GetInstance().createBrowserWindow(app.getAppPath()+"/_doc/README.html")}},{label:"Cryptocalc Test protocols",click(){ElectronMain.GetInstance().createBrowserWindow(app.getAppPath()+"/tests/_doc/index.html")}},{label:L10nUtils.GetLocalizedMsg("Resources"),submenu:[{label:"Ian Coleman BIP39",click(){ElectronMain.GetInstance().createBrowserWindow("https://iancoleman.io/bip39/")}},{label:"Guarda",click(){ElectronMain.GetInstance().createBrowserWindow("https://guarda.com/")}}]},{label:L10nUtils.GetLocalizedMsg("About"),click(){ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_HELP_ABOUT])}}]}]}createWindow(){pretty_func_header_log("ElectronMain.createWindow"),process.env.ELECTRON_DISABLE_SECURITY_WARNINGS="true",this.MainWindow=new BrowserWindow({width:1040,height:690,icon:path.join(__dirname,"../../icons/Cryptocalc_Icon.png"),webPreferences:{contextIsolation:!0,preload:path.join(__dirname,"./preload.js")}}),MainModel.This.setMainWindow(this.MainWindow);const _=Menu.buildFromTemplate(this.getMenuTemplate());Menu.setApplicationMenu(_),this.MainWindow.webContents.on("did-finish-load",async()=>{Skribi.Initialize(this.app_config),this.app_config=this.readAppConfig(),this.getCmdLineArgs(),Skribi.log(">> "+_CYAN_+"eMain.evtH('"+_YELLOW_+"'did-finish-load'"+_CYAN_+")> this.cmd_line[PROGRAM]: "+_END_+this.cmd_line[PROGRAM]),this.cryptowallet_version=MainModel.This.getAppVersion(),this.updateWindowTitle(),this.MainWindow.webContents.send("fromMain",[FromMain_DID_FINISH_LOAD]),this.MainWindow.webContents.send("fromMain",[FromMain_SET_VARIABLE,APP_VERSION,this.cryptowallet_version]),this.MainWindow.webContents.setWindowOpenHandler(_=>(shell.openExternal(_.url),{action:"deny"})),this.setCallbacks(),this.Options=await this.loadOptions();let _=this.cmd_line[PATH];_.endsWith(".wits")&&(Skribi.log(">> "+_CYAN_+"eMain.evtH('"+_RED_+"'did-finish-load'"+_CYAN_+")> SET_VARIABLE("+WITS_PATH+") in Renderer"+_END_+_),await this.MainWindow.webContents.send("fromMain",[FromMain_SET_VARIABLE,WITS_PATH,_])),await this.doFileNew()});let e=path.join(__dirname,"../../../www/index.html");this.MainWindow.loadFile(e)}async openWits(_){if(null==_)throw new Error("**ERROR** in Cryptocalc: '.wits' path is undefined");if(Skribi.log(">> "+_CYAN_+"eMain.evtH('"+_YELLOW_+"'openWits'"+_CYAN_+")> *TEST* Trying to Open '.wits': "+_END_+_),_.endsWith(".wits")){const e=fs.readFileSync(_,{encoding:"utf8",flag:"r"});let n=JSON.parse(e);this.Options=await this.loadOptions(),await this.MainWindow.webContents.send("fromMain",[FromMain_EXEC_CMD,CMD_OPEN_WALLET,n])}}updateWindowTitle(_,e){let n="Cryptocalc "+this.cryptowallet_version;null!=e&&""!=e&&(n+=" - "+e),null!=_&&""!=_&&(n+=": "+_),this.MainWindow.setTitle(n)}async doFileNew(){Skribi.log(">> "+_CYAN_+"ElectronMain.doFileNew"+_END_),this.Options=await this.loadOptions(),await this.MainWindow.webContents.send("fromMain",[FromMain_FILE_NEW,this.Options])}doFileSave(){Skribi.log(">> "+_CYAN_+"ElectronMain.doFileSave"+_END_),this.MainWindow.webContents.send("fromMain",[FromMain_FILE_SAVE])}doFileSaveAs(){Skribi.log(">> "+_CYAN_+"ElectronMain.doFileSaveAs"+_END_),this.MainWindow.webContents.send("fromMain",[FromMain_FILE_SAVE])}async doFileOpen(_){if(Skribi.log(">> "+_CYAN_+"ElectronMain.doFileOpen"+_END_),null==_){let e=app.getAppPath()+"\\_output";if(_=await this.selectFileWithDialogBox(e,"Wallet Informations","wits"),pretty_log("in_file_path",_),""==_)return}const e=fs.readFileSync(_,{encoding:"utf8",flag:"r"});let n=JSON.parse(e);await this.MainWindow.webContents.send("fromMain",[FromMain_FILE_OPEN,n])}async selectFileWithDialogBox(_,e,n){pretty_func_header_log("ElectronMain.selectFileWithDialogBox");let i="",t=await dialog.showOpenDialog(this.MainWindow,{defaultPath:_,filters:[{name:e,extensions:[n]}],properties:["openFile"]});return t.filePaths.length>0&&(i=t.filePaths[0]),i}async selectFileOrDirectoryPathWithDialogBox(_,e,n,i){pretty_func_header_log("ElectronMain.selectFileOrDirectoryPathWithDialogBox"),null==n&&(n=SELECT_DIRECTORY_PATH_MODE),null==i&&(i=""),pretty_log(">> -=-=-=-=-=-=  selectFileOrDirectoryPathWithDialogBox   path_type: '"+i+"'");let t,o,a="";if(n==SELECT_DIRECTORY_PATH_MODE?t=await dialog.showOpenDialog(this.MainWindow,{title:e,defaultPath:_,properties:["openDirectory"],buttonLabel:"Select"}):n==SELECT_FILE_PATH_MODE&&(t=await dialog.showSaveDialog(this.MainWindow,{title:e,defaultPath:_,filters:[{name:"Fichier SQLite",extensions:["db"]}],buttonLabel:"Select",showsTagField:!1}),!t.canceled&&t.filePath&&(console.log("Selected file path:",t.filePath),o=t.filePath)),pretty_log(">> ---------------- selected_file_path: '"+o+"'"),pretty_log(">> ---------------- result.filePaths: '"+t.filePaths+"'"),pretty_log(">> ---------------- result.filePath: '"+t.filePath+"'"),pretty_log(">> ---------------- selected_file_path: '"+o+"'"),null==t.filePaths){if(console.log(">> ********* result.filePaths == undefined\n   selected_file_path: "+o),a=o,!fs.existsSync(a))try{fs.writeFileSync(a,""),console.log("✓ Fichier créé avec succès")}catch(_){console.error("✗ Erreur:",_.message)}}else pretty_log(">> ---------------- result.filePaths.length: '"+t.filePaths.length+"'"),t.filePaths.length>0&&(pretty_log("filePaths: "+JSON.stringify(t.filePaths)),a=t.filePaths[0]);if(i==OUTPUT_DIR_PATH){const _=_=>{const e=/^(\d{4})_(\d{2})_(\d{2})_(\d{2})h-(\d{2})m-(\d{2})s-(\d+)_([A-Z]{3,4})_([A-Z]{2})$/;try{const n=_.match(e);if(!n)return!1;parseInt(n[1],10);const i=parseInt(n[2],10),t=parseInt(n[3],10),o=parseInt(n[4],10),a=parseInt(n[5],10),r=parseInt(n[6],10);parseInt(n[7],10);if(i<1||i>12)return!1;if(t<1||t>31)return!1;if(o<0||o>23)return!1;if(a<0||a>59)return!1;if(r<0||r>59)return!1;n[8],n[9]}catch(_){return console.log("** Parsing Error ** in ElectronMain.selectFileOrDirectoryPathWithDialogBox.validate_output_path"),!1}return!0};let e=!1;const n=fs.readdirSync(a,{withFileTypes:!0});for(let i=0;i<n.length;i++){let t=n[i];console.log("> -------- current_sub_dir.path["+i+"]: "+t.path);let o=t.name;console.log("> -------- subdir_name["+i+"]: "+o);let r=_(o);if(console.log("> -------- valid_as_ouput_dir_path["+i+"]: "+r),r){let _=t.path+"\\"+o+"\\wallet_info.wits";if(console.log("> wits_file_path["+i+"]: "+_),fs.existsSync(_))return e=!0,a}}if(!e)return INVALID_OUTPUT_DIR_PATH}return a}showFolderInExplorer(){pretty_func_header_log("ElectronMain.showFolderInExplorer");let _=os.platform(),e="/",n=this.output_path;"win32"==_?e="\\":_==LINUX&&(e="/"),n=this.output_path.replaceAll("\\","\0").replaceAll("/","\0");let i=n.split("\0");i.pop();n=i.join(e);"win32"==_?shell.openPath(n):_==LINUX&&(n=n.replaceAll("\\","/"),(_=>{exec(`xdg-open "${_}"`,_=>{_&&console.error(`Error opening folder: ${_}`)})})(n))}getNewFortuneCookie(){pretty_func_header_log("ElectronMain.getNewFortuneCookie");let _=getFortuneCookie();Skribi.log("   fortune_cookie: "+getShortenedString(_)),this.MainWindow.webContents.send("fromMain",[FromMain_SET_FORTUNE_COOKIE,_])}toggleDebugPanel(){pretty_func_header_log("ElectronMain.toggleDebugPanel"),this.Show_DebugPanel=!this.Show_DebugPanel,this.Show_DebugPanel?this.MainWindow.webContents.openDevTools():this.MainWindow.webContents.closeDevTools()}readAppConfig(){pretty_func_header_log("ElectronMain.readAppConfig");let _=DEFAULT_APP_CONFIG,e=app.getAppPath()+"/www/config"+"/app_config.json";if(fs.existsSync(e)){const n=fs.readFileSync(e);""!=n&&"[]"!=n&&"{}"!=n&&(_=JSON.parse(n))}return _}readOptionsFile(){pretty_func_header_log("ElectronMain.readOptionsFile");let _=DEFAULT_OPTIONS,e=app.getAppPath()+"/www/config"+"/options.json";if(fs.existsSync(e)){const n=fs.readFileSync(e);""!=n&&"[]"!=n&&"{}"!=n&&(_=JSON.parse(n))}return _}async loadOptions(){return pretty_func_header_log("ElectronMain.loadOptions"),this.Options=this.readOptionsFile(),await this.MainWindow.webContents.send("fromMain",[FromMain_UPDATE_OPTIONS,this.Options]),this.Options}async setDefaultOptions(){pretty_func_header_log("ElectronMain.setDefaultOptions"),this.Options=DEFAULT_OPTIONS,await this.saveOptions(this.Options)}async updateOptions(_){pretty_func_header_log("ElectronMain.updateOptions"),this.Options=_,Skribi.log("   this.Options: "+JSON.stringify(this.Options))}async saveOptions(_){pretty_func_header_log("ElectronMain.saveOptions"),this.Options=_;let e=app.getAppPath()+"/www/config"+"/options.json";fs.writeFileSync(e,JSON.stringify(this.Options)),Skribi.log(" B this.Options: "+JSON.stringify(this.Options)),await this.MainWindow.webContents.send("fromMain",[FromMain_UPDATE_OPTIONS,_])}async resetOptions(){pretty_func_header_log("ElectronMain.resetOptions");let _=app.getAppPath()+"/www/config"+"/defaults/options.json",e=fs.readFileSync(_).toString();Skribi.log("   default_options_str: "+e),this.Options=JSON.parse(e),await this.saveOptions(this.Options)}setCallbacks(){Skribi.log(">> "+_CYAN_+"ElectronMain.setCallbacks"+_END_),ipcMain.handle(ToMain_RQ_QUIT_APP,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_QUIT_APP),app.quit()}),ipcMain.handle(ToMain_RQ_EXEC_CMD,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_EXEC_CMD);const{cmd_name:n,cmd_args:i}=e;Skribi.log("eMain.evtH('ExecCmd')> cmd_name: "+n),Skribi.log("eMain.evtH('ExecCmd')> cmd_args: "+i),n==CMD_OPEN_WALLET&&await ElectronMain.GetInstance().openWits(i)}),ipcMain.on(ToMain_RQ_LOG_2_MAIN,(_,e)=>{Skribi.log(e)}),ipcMain.handle(ToMain_RQ_LOG_2_MAIN_SYNC,async(_,e)=>{Skribi.log(e)}),ipcMain.handle(ToMain_RQ_GET_APP_PATH,async(_,e)=>(pretty_func_header_log("[Electron]",ToMain_RQ_GET_APP_PATH),app.getAppPath())),ipcMain.on(ToMain_RQ_SET_WINDOW_TITLE,(_,e)=>{const{coin:n,wallet_mode:i}=e;ElectronMain.GetInstance().updateWindowTitle(n,i)}),ipcMain.on(ToMain_RQ_TOGGLE_DEBUG_PANEL,(_,e)=>{ElectronMain.GetInstance().toggleDebugPanel()}),ipcMain.on(ToMain_RQ_SHOW_OUTPUT_FOLDER_IN_EXPLORER,(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_SHOW_OUTPUT_FOLDER_IN_EXPLORER),this.showFolderInExplorer()}),ipcMain.on(ToMain_RQ_OPEN_URL,(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_OPEN_URL),Skribi.log("eMain.evtH('OpnURL')> "+e),this.MainWindow.location=e}),Skribi.log(">> register ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG: '"+ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG+"'"),ipcMain.handle(ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_SELECT_FILE_OR_DIRECTORY_PATH_DIALOG),Skribi.log("eMain.evtH('selectFileOrDirPath')>");let{default_path:n,title:i,select_mode:t,path_type:o}=e;return await ElectronMain.GetInstance().selectFileOrDirectoryPathWithDialogBox(n,i,t,o)}),Skribi.log(">> register ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE: '"+ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE+"'"),ipcMain.handle(ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_IMPORT_OUTPUT_FILES_IN_DATABASE),Skribi.log("eMain.evtH(importOutpuFilesInDB')>");let{output_dirs_path:n,db_path:i}=e;await SqLiteUtils.This.importWallets(n,i)}),ipcMain.handle(ToMain_RQ_NEW_WALLET_INFO,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_NEW_WALLET_INFO),Skribi.log("eMain.evtH('NewWinf')>"),await ElectronMain.GetInstance().doFileNew()}),ipcMain.handle(ToMain_RQ_OPEN_WALLET_INFO,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_OPEN_WALLET_INFO),await ElectronMain.GetInstance().doFileOpen()}),ipcMain.handle(ToMain_RQ_SAVE_WALLET_INFO,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_SAVE_WALLET_INFO),Skribi.log("eMain.evtH('SaveWinf')>"),this.output_path=await MainModel.This.saveWalletInfo(e)}),ipcMain.handle(ToMain_RQ_RESET_OPTIONS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_RESET_OPTIONS),Skribi.log("eMain.evtH('RstOpt')>"),ElectronMain.GetInstance().resetOptions()}),ipcMain.handle(ToMain_RQ_UPDATE_OPTIONS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_UPDATE_OPTIONS),null==e&&(Skribi.log(">> "+_RED_+ToMain_RQ_QUIT_APP+_END_),app.quit()),this.Options=e,Skribi.log("eMain.evtH('UpOpt')> this.Options: "+JSON.stringify(this.Options)),await this.MainWindow.webContents.send("fromMain",[FromMain_UPDATE_OPTIONS,this.Options])}),ipcMain.handle(ToMain_RQ_GET_OPTIONS,async(_,e)=>(pretty_func_header_log("[Electron]",ToMain_RQ_GET_OPTIONS),this.Options)),ipcMain.handle(ToMain_RQ_SAVE_OPTIONS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_SAVE_OPTIONS);let n=e;pretty_log("eMain.evtH('SaveOpt')> options_data: "+JSON.stringify(n)),ElectronMain.GetInstance().saveOptions(n),pretty_log("eMain.evtH('SaveOpt')> this.Options: "+JSON.stringify(this.Options)),await this.MainWindow.webContents.send("fromMain",[FromMain_UPDATE_OPTIONS,n])});const _=_=>{let e=fs.readFileSync(_,{encoding:"base64"}),n=_.split("."),i="png",t=n.length;return t>1&&(i=n[t-1].toLowerCase(),"jpg"==i?i="jpeg":"svg"==i&&(i="svg+xml")),this.MainWindow.webContents.send("fromMain",[FromMain_SEND_IMG_URL,ENTROPY_SOURCE_IMG_ID,e,i]),e};ipcMain.handle(ToMain_RQ_LOAD_IMG_FROM_FILE,async(e,n)=>(pretty_func_header_log("[Electron]",ToMain_RQ_LOAD_IMG_FROM_FILE),_(n))),ipcMain.handle(ToMain_RQ_DRAW_RND_CRYPTO_LOGO,(e,n)=>{pretty_func_header_log("[Electron]",ToMain_RQ_DRAW_RND_CRYPTO_LOGO);let i=app.getAppPath()+"/www/img/CryptoCurrency",t=FileUtils.GetFilesInFolder(i),o=i+"/",a="Zilver_64px.svg";if(!this.FirstImageAsEntropySource){a=t[getRandomInt(t.length)]}return this.FirstImageAsEntropySource=!1,o+=a,_(o)}),ipcMain.handle(ToMain_RQ_GENERATE_ENTROPY,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_GENERATE_ENTROPY);return getRandomHexValue(e/8)}),ipcMain.handle(ToMain_RQ_GENERATE_PASSWORD,async(_,e)=>(pretty_func_header_log("[Electron]",ToMain_RQ_GENERATE_PASSWORD),PasswordGenerator.generate({length:24,numbers:!0,symbols:!0,uppercase:!0,lowercase:!0,excludeSimilarCharacters:!0,strict:!0}))),ipcMain.handle(ToMain_RQ_FROM_HEX_CONVERSIONS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_FROM_HEX_CONVERSIONS);let n=e;const i=_=>/^[a-zA-Z0-9À-ÿ\s\p{P}\p{S}]+$/u.test(_);let t="",o="",a="",r="";return t=(_=>{let e=_.toString();console.log("   hex_str: "+e);let n="";for(let _=0;_<e.length;_+=2){let t=e.substr(_,2),o=parseInt(t,16),a=String.fromCharCode(o);i(a)&&(n+=a)}return n})(n),o=hexToB64(n),a=hexToB58(n),r=hexToBinary(n),{[TO_RAW_TEXT]:t,[TO_BASE64]:o,[TO_BASE58]:a,[TO_BINARY]:r}}),ipcMain.handle(ToMain_RQ_TO_HEX_CONVERSIONS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_TO_HEX_CONVERSIONS);let n=e;let i="";return null!=n[FROM_RAW_TEXT]&&""!=n[FROM_RAW_TEXT]?i=(_=>{let e=[];for(let n=0;n<_.length;n++){let i=_.charCodeAt(n).toString(16).padStart(2,"0");e.push(i)}return e.join("")})(n[FROM_RAW_TEXT]):null!=n[FROM_BASE64]&&""!=n[FROM_BASE64]?i=b64ToHex(n[FROM_BASE64]):null!=n[FROM_BASE58]&&""!=n[FROM_BASE58]?i=b58ToHex(n[FROM_BASE58]):null!=n[FROM_BINARY]&&""!=n[FROM_BINARY]&&(i=binaryToHex(n[FROM_BINARY])),i}),ipcMain.handle(ToMain_RQ_BIP85_DERIVE_BIP39,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_BIP85_DERIVE_BIP39);const{entropy:n,bip85_index:i,bip85_entropy_size:t}=e;return Bip85Utils.This.deriveToBip85Infos(n,i,t)}),ipcMain.handle(ToMain_RQ_BIP38_ENCRYPT,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_BIP38_ENCRYPT);const{private_key:n,passphrase:i}=e;return await Bip38Utils.This.encrypt(n,i,this.getMainWindow())}),ipcMain.handle(ToMain_RQ_BIP38_DECRYPT,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_BIP38_DECRYPT);const{bip38_encrypted_pk:n,passphrase:i}=e;return await Bip38Utils.This.decrypt(n,i,this.getMainWindow())}),ipcMain.handle(ToMain_RQ_GET_PASSWORD_STRENGTH,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_GET_PASSWORD_STRENGTH);const n=e;return PasswordStrengthEvaluator.This.getPasswordStrengthInfo(n)}),ipcMain.handle(ToMain_RQ_GET_HD_WALLET,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_GET_HD_WALLET+"======================");const{entropy_hex:n,salt_uuid:i,blockchain:t,crypto_net:o,bip32_passphrase:a,account:r,address_index:l,bip32_protocol:s}=e;pretty_log("bip32_protocol",s);let E={[BLOCKCHAIN]:t,[CRYPTO_NET]:o,[BIP39_PASSPHRASE]:a,[BIP32_PROTOCOL]:s,[ACCOUNT]:r,[ADDRESS_INDEX]:l};return await HDWallet.GetWallet(n,i,E)}),ipcMain.handle(ToMain_RQ_GET_SIMPLE_WALLET,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_GET_SIMPLE_WALLET);const{private_key:n,salt_uuid:i,blockchain:t,crypto_net:o}=e;if(null==n||""==n)throw new Error("ElectronMain ToMain_RQ_GET_SIMPLE_WALLET handler: 'private_key' NOT DEFINED");return await SimpleWallet.GetWallet(n,i,t,o)}),ipcMain.handle(ToMain_RQ_MNEMONICS_TO_HD_WALLET_INFO,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_MNEMONICS_TO_HD_WALLET_INFO+"=)=)=)=)=)=)=)=)=)=)");const{mnemonics:n,options:i}=e;return await Bip32Utils.MnemonicsToHDWalletInfo(n,i)}),ipcMain.handle(ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO);const{mnemonics:n,lang:i}=e;return Bip39Utils.MnemonicsToEntropyInfo(n,i)}),ipcMain.handle(ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO_CUSTOM,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_MNEMONICS_TO_ENTROPY_INFO_CUSTOM);const{mnemonics:n,lang:i}=e;return Bip39Utils.MnemonicsToEntropyInfoCustom(n,i)}),ipcMain.handle(ToMain_RQ_ENTROPY_TO_MNEMONICS,async(_,e)=>{const{entropy:n,lang:i}=e;return Bip39Utils.EntropyToMnemonics(n,i)}),ipcMain.handle(ToMain_RQ_ENTROPY_TO_CHECKSUM,async(_,e)=>{const{entropy:n,options:i}=e;return Bip39Utils.EntropyToChecksum(n,i)}),ipcMain.handle(ToMain_RQ_ENTROPY_SRC_TO_ENTROPY,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_ENTROPY_SRC_TO_ENTROPY);const{salted_entropy_src_str:n,options:i}=e;return Bip39Utils.EntropySourceToEntropy(n,i)}),ipcMain.handle(ToMain_RQ_MNEMONICS_AS_4LETTER,async(_,e)=>Bip39Utils.MnemonicsAs4letter(e)),ipcMain.handle(ToMain_RQ_MNEMONICS_AS_TWO_PARTS,async(_,e)=>Bip39Utils.MnemonicsAsTwoParts(e)),ipcMain.handle(ToMain_RQ_GET_FORTUNE_COOKIE,async(_,e)=>(pretty_func_header_log("[Electron]",ToMain_RQ_GET_FORTUNE_COOKIE),this.getNewFortuneCookie())),ipcMain.handle(ToMain_RQ_WORD_INDEX_TO_MNEMONIC,async(_,e)=>{Skribi.log(">> "+_CYAN_+"[Electron] "+_YELLOW_+ToMain_RQ_WORD_INDEX_TO_MNEMONIC+_END_);const{word_index:n,lang:i}=e;return Bip39Utils.GetMnemonicFromWordIndex(n,i)}),ipcMain.handle(ToMain_RQ_WORD_INDEXES_TO_MNEMONICS,async(_,e)=>{Skribi.log(">> "+_CYAN_+"[Electron] "+_YELLOW_+ToMain_RQ_WORD_INDEXES_TO_MNEMONICS+_END_);const{word_indexes:n,lang:i}=e;return Bip39Utils.WordIndexesToMnemonics(n,i)}),ipcMain.handle(ToMain_RQ_MNEMONIC_TO_WORD_INDEX,async(_,e)=>{Skribi.log(">> "+_CYAN_+"[Electron] "+_YELLOW_+ToMain_RQ_MNEMONIC_TO_WORD_INDEX+_END_);let{mnemonics:n,options:i}=e;n=n.normalize("NFC"),console.log(">> "+ToMain_RQ_MNEMONIC_TO_WORD_INDEX+"  mnemonics: "+JSON.stringify(n)),console.log(">> "+ToMain_RQ_MNEMONIC_TO_WORD_INDEX+"  options: "+JSON.stringify(i));let t=Bip39Utils.GetWordIndexes(n,i);console.log(">> "+ToMain_RQ_MNEMONIC_TO_WORD_INDEX+"  word_indexes: "+JSON.stringify(t)),console.log(">> "+ToMain_RQ_MNEMONIC_TO_WORD_INDEX+"  word_indexes.length: "+t.length);let o=-1;return 1==t.length&&(o=t[0]),o}),ipcMain.handle(ToMain_RQ_MNEMONICS_TO_WORD_INDEXES,async(_,e)=>{const{mnemonics:n,options:i}=e;return Bip39Utils.GetWordIndexes(n,i)}),ipcMain.handle(ToMain_RQ_GUESS_MNEMONICS_LANG,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_GUESS_MNEMONICS_LANG);const{mnemonics:n}=e;return Bip39Utils.GuessMnemonicsLang(n)}),ipcMain.handle(ToMain_RQ_CHECK_MNEMONICS,async(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_CHECK_MNEMONICS);const{mnemonics:n,options:i}=e;return Bip39Utils.CheckMnemonics(n,i)}),ipcMain.handle(ToMain_RQ_GET_UUID,async(_,e)=>uuidv4()),ipcMain.handle(ToMain_RQ_GET_L10N_KEYPAIRS,(_,e)=>L10nUtils.GetKeyPairs()),ipcMain.handle(ToMain_RQ_GET_L10N_MSG,(_,e)=>L10nUtils.GetLocalizedMsg(e)),ipcMain.on(ToMain_RQ_SET_MENU_ITEM_STATE,(_,e)=>{pretty_func_header_log("[Electron]",ToMain_RQ_SET_MENU_ITEM_STATE);const{menu_item_id:n,enabled:i}=e;Menu.getApplicationMenu().getMenuItemById(n).enabled=i})}getEntropyBip39ByteCount(_){if(!isHexString(_)||_.length%2!=0)return 0;let e=_.length/2;return-1!=[16,20,24,28,32].indexOf(e)?e:0}}gotTheLock?(app.on("second-instance",(_,e,n)=>{let i=ElectronMain.GetInstance().getMainWindow();null!=i&&(i&&i.restore(),i.focus())}),app.whenReady().then(async()=>{if(process.platform.startsWith("win")&&process.argv.length>=2){process.argv[1]}ElectronMain.GetInstance().createWindow();let _=!0;const e=async()=>{_=!0,await checkInternetConnected().catch(e=>{_=!1}),ElectronMain.GetInstance().getMainWindow().webContents.send("fromMain",[FromMain_INTERNET_CONNECTED,_]),setTimeout(e,1250)};await e()})):app.quit();
//# sourceMappingURL=/sm/166ce8f8f8e86b21aa7cbc03b48f6ade3bfc567333e21ecf2a78f9f7e05b38b2.map