Skip to content

Commit

Permalink
Types
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Apr 11, 2022
1 parent 865b9e8 commit 0841e90
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 124 deletions.
16 changes: 8 additions & 8 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const chooseImportFile = () => {
filters: [{ name: lang.application_dialog.authme_file, extensions: ["authme"] }],
})
.then((result) => {
canceled = result.canceled
filepath = result.filePaths
const canceled = result.canceled
const filepath = result.filePaths

if (canceled === false) {
const /** @type{LibAuthmeFile} */ loaded = JSON.parse(fs.readFileSync(filepath.toString(), "utf-8"))
Expand Down Expand Up @@ -149,10 +149,10 @@ const importExistingCodes = async (res) => {

fs.readFile(path.join(folder_path, "codes", "codes.authme"), async (err, content) => {
if (err) {
logger.error(err)
logger.error("Error loading codes", err)
}

const codes_file = JSON.parse(content)
const codes_file = JSON.parse(content.toString())

const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)

Expand Down Expand Up @@ -308,7 +308,7 @@ const generateCodeElements = (data) => {
// set content
name.textContent = issuers[i]
code.textContent = token
time.textContent = remaining_time
time.textContent = remaining_time.toString()
}
}

Expand Down Expand Up @@ -341,7 +341,7 @@ const generateCodeElements = (data) => {

/**
* Refresh codes every 500ms
* @param {number} secrets
* @param {string[]} secrets
*/
const refreshCodes = (secrets) => {
for (let i = 0; i < secrets.length; i++) {
Expand All @@ -359,7 +359,7 @@ const refreshCodes = (secrets) => {

// set content
code.textContent = token
time.textContent = remaining
time.textContent = remaining.toString()
}
}

Expand Down Expand Up @@ -594,7 +594,7 @@ const loadCodes = async () => {
password.fill(0)
key.fill(0)
} else {
const codes_file = JSON.parse(content)
const codes_file = JSON.parse(content.toString())

if (codes_file.version === 3) {
const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)
Expand Down
7 changes: 4 additions & 3 deletions app/confirm/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ const text = document.querySelector("#text")
/**
* Confirm password on enter press
*/
document.querySelector("#password_input").addEventListener("keypress", (e) => {
if (e.key === "Enter") {
document.querySelector("#password_input").addEventListener("keypress", (event) => {
// @ts-ignore
if (event.key === "Enter") {
check_integrity()

setTimeout(() => {
Expand Down Expand Up @@ -155,7 +156,7 @@ const unhashPassword = async () => {
// compare
const password_input = Buffer.from(document.querySelector("#password_input").value)

const compare = await bcrypt.compare(password_input.toString(), settings.security.password).then(logger.log("Passwords compared!"))
const compare = await bcrypt.compare(password_input.toString(), settings.security.password)

if (compare == true) {
ipc.invoke("sendPassword", password_input)
Expand Down
16 changes: 7 additions & 9 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const generateEditElements = () => {
</div>
`

div.setAttribute("id", counter)
div.setAttribute("id", counter.toString())
codes_container.appendChild(div)

counter++
Expand All @@ -241,8 +241,8 @@ let edit_mode = false

const editCode = (number) => {
const edit_button = document.querySelector(`#edit_but_${number}`)
const issuer_input = document.querySelector(`#edit_issuer_${number}`)
const name_input = document.querySelector(`#edit_name_${number}`)
const /** @type{HTMLInputElement} */ issuer_input = document.querySelector(`#edit_issuer_${number}`)
const /** @type{HTMLInputElement} */ name_input = document.querySelector(`#edit_name_${number}`)

name_input.focus()
const length = name_input.value.length
Expand Down Expand Up @@ -416,8 +416,8 @@ const addCodes = () => {
filters: [{ name: lang.application_dialog.authme_file, extensions: ["authme"] }],
})
.then((result) => {
canceled = result.canceled
files = result.filePaths
const canceled = result.canceled
const files = result.filePaths

if (canceled === false) {
for (let i = 0; i < files.length; i++) {
Expand All @@ -430,8 +430,6 @@ const addCodes = () => {
const /** @type{LibAuthmeFile} */ loaded = JSON.parse(input.toString())

if (loaded.role === "import" || loaded.role === "export") {
data = []

const container = document.querySelector(".codes_container")
container.innerHTML = ""

Expand Down Expand Up @@ -564,7 +562,7 @@ const loadCodes = async () => {
password.fill(0)
key.fill(0)
} else {
const codes_file = JSON.parse(content)
const codes_file = JSON.parse(content.toString())

const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)

Expand Down Expand Up @@ -609,7 +607,7 @@ const loadCodes = async () => {
password.fill(0)
key.fill(0)
} else {
const codes_file = JSON.parse(content)
const codes_file = JSON.parse(content.toString())

const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)

Expand Down
10 changes: 5 additions & 5 deletions app/export/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const saveFile = () => {
defaultPath: "~/export.authme",
})
.then((result) => {
canceled = result.canceled
output = result.filePath
const canceled = result.canceled
const output = result.filePath

/**
* .authme export file
Expand Down Expand Up @@ -178,8 +178,8 @@ const saveQrCodes = () => {
defaultPath: "~/authme_export.html",
})
.then((result) => {
canceled = result.canceled
output = result.filePath
const canceled = result.canceled
const output = result.filePath

if (canceled === false) {
let string = ""
Expand Down Expand Up @@ -252,7 +252,7 @@ const exportCodes = async () => {

error()
} else {
const codes_file = JSON.parse(content)
const codes_file = JSON.parse(content.toString())

const decrypted = aes.decrypt(Buffer.from(codes_file.codes, "base64"), key)

Expand Down
1 change: 0 additions & 1 deletion app/import/src/js/images.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
/**
* Read QR code(s) from image(s)
* @param {string[]} images
*/
chooseImages: async () => {
let string = ""
Expand Down
8 changes: 4 additions & 4 deletions app/landing/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ const text = document.querySelector("#text")
let storage = {}

if (dev === false) {
temp_storage = localStorage.getItem("storage")
const temp_storage = localStorage.getItem("storage")

if (temp_storage === null) {
localStorage.setItem("storage", JSON.stringify(storage))
}
} else {
temp_storage = localStorage.getItem("dev_storage")
const temp_storage = localStorage.getItem("dev_storage")

if (temp_storage === null) {
localStorage.setItem("dev_storage", JSON.stringify(storage))
Expand Down Expand Up @@ -131,7 +131,7 @@ const hashPasswords = async () => {
const password_input = Buffer.from(document.querySelector("#password_input1").value)

const salt = await bcrypt.genSalt(10)
const hashed = await bcrypt.hash(password_input.toString(), salt).then(logger.log("Hash completed!"))
const hashed = await bcrypt.hash(password_input.toString(), salt)

/**
* Read settings
Expand Down Expand Up @@ -196,7 +196,7 @@ const noPassword = () => {

storage.require_password = settings.security.require_password
storage.password = password.toString("base64")
storage.key = salt.toString("base64")
storage.key = salt

dev ? localStorage.setItem("dev_storage", JSON.stringify(storage)) : localStorage.setItem("storage", JSON.stringify(storage))

Expand Down
24 changes: 12 additions & 12 deletions app/settings/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,12 @@ const clearData = () => {
})
.then(async (result) => {
if (result.response === 0) {
// clear codes
await fs.promises.rm(folder_path, { recursive: true, force: true }, (err) => {
if (err) {
return logger.error("Error deleting settings folder", err.stack)
} else {
logger.log("Setting folder deleted")
}
})
// delete folders
try {
await fs.promises.rm(folder_path, { recursive: true, force: true })
} catch (error) {
logger.log("Error deleting folders", error)
}

// remove startup shortcut
if (dev === false) {
Expand Down Expand Up @@ -763,9 +761,8 @@ const menu = (name) => {
document.querySelector(".experimental").disabled = false
document.querySelector(".codes").disabled = false

// @ts-ignore
window.location = `${`${window.location}`.replace(/#[A-Za-z0-9_]*$/, "")}#header`

shortcut = true
} else if (name === "general") {
storage.settings_page = "general"

Expand All @@ -778,6 +775,7 @@ const menu = (name) => {
document.querySelector(".experimental").disabled = false
document.querySelector(".codes").disabled = false

// @ts-ignore
window.location = `${`${window.location}`.replace(/#[A-Za-z0-9_]*$/, "")}#header`
} else if (name === "experimental") {
storage.settings_page = "experimental"
Expand All @@ -791,6 +789,7 @@ const menu = (name) => {
document.querySelector(".shortcuts").disabled = false
document.querySelector(".codes").disabled = false

// @ts-ignore
window.location = `${`${window.location}`.replace(/#[A-Za-z0-9_]*$/, "")}#header`
} else if (name === "codes") {
storage.settings_page = "codes"
Expand All @@ -804,6 +803,7 @@ const menu = (name) => {
document.querySelector(".shortcuts").disabled = false
document.querySelector(".codes").disabled = true

// @ts-ignore
window.location = `${`${window.location}`.replace(/#[A-Za-z0-9_]*$/, "")}#header`
}

Expand Down Expand Up @@ -910,7 +910,7 @@ const showPassword = (id) => {

/* Show/hide load backup file dialog */
const loadBackupFileDialog = () => {
const dialog = document.querySelector(".dialog1")
const /** @type{LibDialogElement} */ dialog = document.querySelector(".dialog1")
const close_dialog = document.querySelector(".dialog1Close")

close_dialog.addEventListener("click", () => {
Expand All @@ -922,7 +922,7 @@ const loadBackupFileDialog = () => {

/* Show/hide change password dialog */
const changePasswordDialog = () => {
const dialog = document.querySelector(".dialog0")
const /** @type{LibDialogElement} */ dialog = document.querySelector(".dialog0")
const close_dialog = document.querySelector(".dialog0Close")

close_dialog.addEventListener("click", () => {
Expand Down
11 changes: 11 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2021",
"checkJs": true,
"strictFunctionTypes": true,
"resolveJsonModule": true
},
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion languages/hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ module.exports = {
],

"import_dialog": {
"import_qrcode": "Importálás QR-kódokból",
"choose_images": "Importálás QR-kódokból",
"image_file": "Kép fájl",
"save_file": "Fájl mentése",
"no_webcam": "Nem található webkamera! \n\nEllenőrizd hogy a webkamerád megfelelően működik vagy nem használja más alkamazás.",
Expand Down
6 changes: 3 additions & 3 deletions lib/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {

/**
* Generate random key
* @param {Buffer} salt
* @param {Buffer|string} salt
* @return {Buffer} key
*/
generateRandomKey: (salt) => {
Expand All @@ -29,7 +29,7 @@ module.exports = {

/**
* Generate key from password and salt
* @param {string} password
* @param {Buffer} password
* @param {Buffer} salt
* @return {Buffer} key
*/
Expand All @@ -55,7 +55,7 @@ module.exports = {

/**
* Decrypt a string
* @param {string} text
* @param {Buffer} text
* @param {Buffer} key
* @returns {Buffer} decrypted text
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const electron = require("electron")
module.exports = {
/**
* Localize the page
* @param {renderer} rendererName
* @param {string} renderer
*/
localize: (renderer) => {
const res = electron.ipcRenderer.sendSync("languageCode").language
Expand Down
4 changes: 0 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const aes = require("./aes")
const rsa = require("./rsa")
const sha = require("./sha")
const markdown = require("./markdown")
const qrcodeConverter = require("./qrcodeConverter")
const typedef = require("./typedef")
const convert = require("./convert")
const time = require("./time")
const password = require("./password/index")
Expand All @@ -12,11 +10,9 @@ const localization = require("./localization")
// ? export modules
module.exports = {
aes,
rsa,
sha,
markdown,
qrcodeConverter,
typedef,
convert,
time,
password,
Expand Down
Loading

0 comments on commit 0841e90

Please sign in to comment.