-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: removed keytar due to arm64 lib issues, new encrypted store add…
…ed for keytar replacement
- Loading branch information
Showing
8 changed files
with
240 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ytmdesktop2", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"private": false, | ||
"author": "Venipa <[email protected]>", | ||
"main": "./out/main/index.js", | ||
|
@@ -35,17 +35,18 @@ | |
"chalk": "^5.0.1", | ||
"core-js": "^3.24.1", | ||
"cors": "^2.8.5", | ||
"crypto-js": "^4.2.0", | ||
"daisyui": "^2.20.0", | ||
"date-fns": "^2.29.1", | ||
"dompurify": "^3.1.7", | ||
"electron-conf": "^1.2.1", | ||
"electron-threads": "^1.0.2", | ||
"electron-updater": "^6.3.9", | ||
"encryption.js": "^1.0.6", | ||
"events": "^3.3.0", | ||
"express": "^4.18.1", | ||
"express-ws": "^5.0.2", | ||
"got": "^11.8.6", | ||
"keytar": "^7.9.0", | ||
"lodash-es": "^4.17.21", | ||
"lucide-vue-next": "^0.454.0", | ||
"node-fetch": "^2.6.7", | ||
|
@@ -72,6 +73,7 @@ | |
"@electron-toolkit/tsconfig": "^1.0.1", | ||
"@rushstack/eslint-patch": "^1.10.4", | ||
"@types/cors": "^2.8.17", | ||
"@types/crypto-js": "^4.2.2", | ||
"@types/electron-devtools-installer": "^2.2.0", | ||
"@types/events": "^3.0.0", | ||
"@types/express": "^4.17.13", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { createEncryptedStore } from "../store/createYmlStore"; | ||
type Credential = { | ||
account: string; | ||
password: string; | ||
}; | ||
type Credentials = Array<Credential>; | ||
type CredentialStore = { | ||
credentials: Record<string, any | null | undefined>; | ||
}; | ||
const store = createEncryptedStore<CredentialStore>("credentials", { | ||
defaults: { credentials: {} }, | ||
}); | ||
class SecureStore { | ||
getAll() { | ||
return new Promise<Credentials>((resolve, reject) => | ||
resolve( | ||
Object.entries(store.get("credentials", {})).map( | ||
([account, password]) => | ||
({ | ||
account, | ||
password, | ||
}) as Credential, | ||
), | ||
), | ||
); | ||
} | ||
set(key: string, value: string) { | ||
return new Promise<string | null>(async (resolve, reject) => { | ||
store.set({ | ||
credentials: { | ||
[key]: value, | ||
}, | ||
}); | ||
return resolve(value); | ||
}); | ||
} | ||
get<T = any>(key: string) { | ||
return new Promise<T | null>(async (resolve, reject) => { | ||
const value = store.get(`credentials.${key}`, null); | ||
return resolve(value); | ||
}); | ||
} | ||
delete(key: string) { | ||
return new Promise<boolean>(async (resolve, reject) => { | ||
store.delete(`credentials.${key}`); | ||
return resolve(true); | ||
}); | ||
} | ||
readonly setPassword: typeof this.set = this.set.bind(this); | ||
readonly getPassword: typeof this.get = this.get.bind(this); | ||
} | ||
|
||
const secureStore = new SecureStore(); | ||
export default secureStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Buffer } from 'buffer'; | ||
|
||
/* | ||
* @poppinss/utils | ||
* | ||
* (c) Poppinss | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/** | ||
* Helper class to base64 encode/decode values with option | ||
* for url encoding and decoding | ||
*/ | ||
class Base64 { | ||
/** | ||
* Base64 encode Buffer or string | ||
*/ | ||
encode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string; | ||
encode(data: string, encoding?: BufferEncoding): string; | ||
encode(data: ArrayBuffer | SharedArrayBuffer | string, encoding?: BufferEncoding): string { | ||
if (typeof data === 'string') { | ||
return Buffer.from(data, encoding).toString('base64'); | ||
} | ||
return Buffer.from(data).toString('base64'); | ||
} | ||
|
||
/** | ||
* Base64 decode a previously encoded string or Buffer. | ||
*/ | ||
decode(encode: string, encoding: BufferEncoding, strict: true): string; | ||
decode(encode: string, encoding: undefined, strict: true): string; | ||
decode(encode: string, encoding?: BufferEncoding, strict?: false): string | null; | ||
decode(encode: Buffer, encoding?: BufferEncoding): string; | ||
decode(encoded: string | Buffer, encoding: BufferEncoding = 'utf8', strict: boolean = false): string | null { | ||
if (Buffer.isBuffer(encoded)) { | ||
return encoded.toString(encoding); | ||
} | ||
|
||
const decoded = Buffer.from(encoded, 'base64').toString(encoding); | ||
const isInvalid = this.encode(decoded, encoding) !== encoded; | ||
|
||
if (strict && isInvalid) { | ||
throw new Error('Cannot decode malformed value'); | ||
} | ||
|
||
return isInvalid ? null : decoded; | ||
} | ||
|
||
/** | ||
* Base64 encode Buffer or string to be URL safe. (RFC 4648) | ||
*/ | ||
urlEncode(arrayBuffer: ArrayBuffer | SharedArrayBuffer): string; | ||
urlEncode(data: string, encoding?: BufferEncoding): string; | ||
urlEncode(data: ArrayBuffer | SharedArrayBuffer | string, encoding?: BufferEncoding): string { | ||
const encoded = typeof data === 'string' ? this.encode(data, encoding) : this.encode(data); | ||
return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, ''); | ||
} | ||
|
||
/** | ||
* Base64 URL decode a previously encoded string or Buffer. (RFC 4648) | ||
*/ | ||
urlDecode(encode: string, encoding: BufferEncoding, strict: true): string; | ||
urlDecode(encode: string, encoding: undefined, strict: true): string; | ||
urlDecode(encode: string, encoding?: BufferEncoding, strict?: false): string | null; | ||
urlDecode(encode: Buffer, encoding?: BufferEncoding): string; | ||
urlDecode(encoded: string | Buffer, encoding: BufferEncoding = 'utf8', strict: boolean = false): string | null { | ||
if (Buffer.isBuffer(encoded)) { | ||
return encoded.toString(encoding); | ||
} | ||
|
||
const decoded = Buffer.from(encoded, 'base64').toString(encoding); | ||
const isInvalid = this.urlEncode(decoded, encoding) !== encoded; | ||
|
||
if (strict && isInvalid) { | ||
throw new Error('Cannot urlDecode malformed value'); | ||
} | ||
|
||
return isInvalid ? null : decoded; | ||
} | ||
} | ||
|
||
export const base64 = new Base64(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Buffer } from 'buffer'; | ||
import { enc, lib } from 'crypto-js'; | ||
import { base64 } from './base64'; | ||
/** | ||
* Generates a random string of a given size | ||
*/ | ||
export function generateRandom(size: number): string { | ||
const bits = (size + 1) * 6; | ||
const buffer = Buffer.from(lib.WordArray.random(Math.ceil(bits / 8)).toString(enc.Hex), 'hex'); | ||
return base64.urlEncode(buffer).slice(0, size); | ||
} |
Oops, something went wrong.