Last round of prettier: npx prettier --write src/

This commit is contained in:
Scott Idem
2026-03-24 13:27:40 -04:00
parent 23d25bf65a
commit a8f3c29b9f
146 changed files with 13201 additions and 9277 deletions

View File

@@ -8,12 +8,22 @@ async function generate_iv() {
}
// Updated 2025-05-08
export const encrypt_content = async function encrypt_content(content: string, keyData: string) {
export const encrypt_content = async function encrypt_content(
content: string,
keyData: string
) {
const iv = await generate_iv();
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, [
'encrypt'
]);
const keyBytes = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(keyData)
);
const key = await crypto.subtle.importKey(
'raw',
keyBytes,
{ name: 'AES-CBC' },
false,
['encrypt']
);
const encodedContent = await crypto.subtle.encrypt(
{ name: 'AES-CBC', iv: iv.buffer as ArrayBuffer },
key,
@@ -52,7 +62,10 @@ export const combine_iv_and_base64 = function combine_iv_and_base64(
};
// Updated 2025-05-08
export const encrypt_wrapper = async function encrypt_wrapper(content: string, keyData: string) {
export const encrypt_wrapper = async function encrypt_wrapper(
content: string,
keyData: string
) {
if (!content) {
console.error('No content provided. Returning empty string.');
return '';
@@ -73,11 +86,20 @@ export const decrypt_content = async function decrypt_content(
iv: Uint8Array,
keyData: string
) {
const keyBytes = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(keyData));
const key = await crypto.subtle.importKey('raw', keyBytes, { name: 'AES-CBC' }, false, [
'decrypt'
]);
const encryptedContent = Uint8Array.from(atob(base64Content), (c) => c.charCodeAt(0));
const keyBytes = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(keyData)
);
const key = await crypto.subtle.importKey(
'raw',
keyBytes,
{ name: 'AES-CBC' },
false,
['decrypt']
);
const encryptedContent = Uint8Array.from(atob(base64Content), (c) =>
c.charCodeAt(0)
);
const decryptedContent = await crypto.subtle.decrypt(
{ name: 'AES-CBC', iv: iv.buffer as ArrayBuffer },
key,
@@ -89,7 +111,9 @@ export const decrypt_content = async function decrypt_content(
};
// Updated 2025-05-08
export const split_iv_and_base64 = function split_iv_and_base64(combined: string) {
export const split_iv_and_base64 = function split_iv_and_base64(
combined: string
) {
if (!combined) {
console.error('No combined string provided. Returning empty object.');
return { iv: new Uint8Array(), base64: '' };
@@ -97,7 +121,9 @@ export const split_iv_and_base64 = function split_iv_and_base64(combined: string
const [iv_hex, encrypted_base64_string] = combined.split(':');
const base64 = encrypted_base64_string;
const match_result = iv_hex.match(/.{1,2}/g);
const iv = new Uint8Array((match_result || []).map((byte) => parseInt(byte, 16)));
const iv = new Uint8Array(
(match_result || []).map((byte) => parseInt(byte, 16))
);
if (log_lvl) {
console.log(`IV: ${iv}; Encrypted:`, base64);
}
@@ -105,7 +131,10 @@ export const split_iv_and_base64 = function split_iv_and_base64(combined: string
};
// Updated 2025-05-15
export const decrypt_wrapper = async function decrypt_wrapper(combined: string, keyData: string) {
export const decrypt_wrapper = async function decrypt_wrapper(
combined: string,
keyData: string
) {
if (!combined) {
console.error('No combined string provided. Returning empty string.');
return false;