Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Change layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jul 14, 2022
1 parent 4539e48 commit 93594df
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 6 deletions.
2 changes: 1 addition & 1 deletion interface/layout/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import Landing from "../windows/landing.svelte"
import Codes from "../windows/codes/codes.svelte"
import Settings from "../windows/settings.svelte"
import Import from "../windows/import.svelte"
import Import from "../windows/import/import.svelte"
import Export from "../windows/export.svelte"
import Confirm from "../windows/confirm.svelte"
import Navigation from "../components/navigation.svelte"
Expand Down
2 changes: 1 addition & 1 deletion interface/index.html → interface/layout/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="./layout/app.ts"></script>
<script type="module" src="./app.ts"></script>
</body>
</html>

5 changes: 5 additions & 0 deletions interface/stores/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { writable } from "svelte/store"

export const state = writable({
importData: null,
})
2 changes: 1 addition & 1 deletion interface/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

.selectedMenuButton {
@apply mx-3 mb-3 flex h-20 w-20 flex-col items-center justify-center rounded-xl bg-white font-medium text-black duration-200 ease-linear hover:bg-gray-200;
@apply mx-3 mb-3 flex h-20 w-20 flex-col items-center justify-center rounded-xl bg-white font-medium !text-black duration-200 ease-linear hover:bg-gray-200;
}

.select {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,17 @@
</div>

<script>
import Details from "../components/details.svelte"
import { onDestroy } from "svelte"
import Details from "../../components/details.svelte"
import { state } from "../../stores/state"
const stateSubscriber = state.subscribe((value) => {
console.log(value)
})
state.set({ importData: "asd" })
onDestroy(() => {
stateSubscriber()
})
</script>
82 changes: 82 additions & 0 deletions libraries/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import crypto from "crypto"

const ALGORITHM = {
BLOCK_CIPHER: "aes-256-gcm",
AUTH_TAG_BYTE_LEN: 16,
IV_BYTE_LEN: 12,
KEY_BYTE_LEN: 32,
SALT_BYTE_LEN: 16,
}

/**
* Generate salt
* @return {Buffer} salt
*/
export const generateSalt = (): Buffer => {
return crypto.randomBytes(ALGORITHM.SALT_BYTE_LEN)
}

/**
* Generate random key
* @param {Buffer|string} salt
* @return {Buffer} key
*/
export const generateRandomKey = (salt: Buffer | string): Buffer => {
const key = crypto.randomBytes(ALGORITHM.KEY_BYTE_LEN)
return crypto.scryptSync(key, salt, ALGORITHM.KEY_BYTE_LEN)
}

/**
* Generate key from password and salt
* @param {Buffer} password
* @param {Buffer} salt
* @return {Buffer} key
*/
export const generateKey = (password: Buffer, salt: Buffer): Buffer => {
return crypto.scryptSync(password, salt, ALGORITHM.KEY_BYTE_LEN)
}

/**
* Encrypt a string
* @param {string} text
* @param {Buffer} key
* @return {Buffer} encrypted text
*/
export const encrypt = (text: string, key: Buffer): Buffer => {
const iv = crypto.randomBytes(ALGORITHM.IV_BYTE_LEN)
const cipher = crypto.createCipheriv(ALGORITHM.BLOCK_CIPHER, key, iv, {
// @ts-ignore
authTagLength: ALGORITHM.AUTH_TAG_BYTE_LEN,
})
let encryptedMessage = cipher.update(text)
encryptedMessage = Buffer.concat([encryptedMessage, cipher.final()])
return Buffer.concat([iv, encryptedMessage, cipher.getAuthTag()])
}

/**
* Decrypt a string
* @param {Buffer} text
* @param {Buffer} key
* @returns {Buffer} decrypted text
*/
export const decrypt = (text: Buffer, key: Buffer): Buffer => {
const authTag = text.slice(-16)
const iv = text.slice(0, 12)
const encryptedMessage = text.slice(12, -16)
const decipher = crypto.createDecipheriv(ALGORITHM.BLOCK_CIPHER, key, iv, {
// @ts-ignore
authTagLength: ALGORITHM.AUTH_TAG_BYTE_LEN,
})
decipher.setAuthTag(authTag)
const messageText = decipher.update(encryptedMessage)
return Buffer.concat([messageText, decipher.final()])
}

/**
*
* @param {string|Buffer} text
* @returns {string} sha512 text
*/
export const hash = (text: string | Buffer): string => {
return crypto.createHash("sha512").update(text).digest("base64")
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"private": true,
"type": "module",
"scripts": {
"dev": "parcel ./interface/index.html --port 3000",
"build": "parcel build ./interface/index.html"
"dev": "parcel ./interface/layout/index.html --port 3000",
"build": "parcel build ./interface/layout/index.html"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
Expand Down

0 comments on commit 93594df

Please sign in to comment.