forked from trent_larson/crowd-funder-for-time-pwa
fix linting (and change a little wording in onboarding page)
This commit is contained in:
@@ -177,43 +177,43 @@ export async function encryptMessage(message: string, password: string) {
|
||||
|
||||
// Derive key from password using PBKDF2
|
||||
const keyMaterial = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
"raw",
|
||||
encoder.encode(password),
|
||||
'PBKDF2',
|
||||
"PBKDF2",
|
||||
false,
|
||||
['deriveBits', 'deriveKey']
|
||||
["deriveBits", "deriveKey"],
|
||||
);
|
||||
|
||||
const key = await crypto.subtle.deriveKey(
|
||||
{
|
||||
name: 'PBKDF2',
|
||||
name: "PBKDF2",
|
||||
salt,
|
||||
iterations: ITERATIONS,
|
||||
hash: 'SHA-256'
|
||||
hash: "SHA-256",
|
||||
},
|
||||
keyMaterial,
|
||||
{ name: 'AES-GCM', length: KEY_LENGTH },
|
||||
{ name: "AES-GCM", length: KEY_LENGTH },
|
||||
false,
|
||||
['encrypt']
|
||||
["encrypt"],
|
||||
);
|
||||
|
||||
// Encrypt the message
|
||||
const encryptedContent = await crypto.subtle.encrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv
|
||||
name: "AES-GCM",
|
||||
iv,
|
||||
},
|
||||
key,
|
||||
encoder.encode(message)
|
||||
encoder.encode(message),
|
||||
);
|
||||
|
||||
// Return a JSON structure with base64-encoded components
|
||||
const result = {
|
||||
salt: arrayBufferToBase64(salt),
|
||||
iv: arrayBufferToBase64(iv),
|
||||
encrypted: arrayBufferToBase64(encryptedContent)
|
||||
encrypted: arrayBufferToBase64(encryptedContent),
|
||||
};
|
||||
|
||||
|
||||
return btoa(JSON.stringify(result));
|
||||
}
|
||||
|
||||
@@ -229,34 +229,34 @@ export async function decryptMessage(encryptedJson: string, password: string) {
|
||||
|
||||
// Derive the same key using PBKDF2 with the extracted salt
|
||||
const keyMaterial = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
"raw",
|
||||
new TextEncoder().encode(password),
|
||||
'PBKDF2',
|
||||
"PBKDF2",
|
||||
false,
|
||||
['deriveBits', 'deriveKey']
|
||||
["deriveBits", "deriveKey"],
|
||||
);
|
||||
|
||||
const key = await crypto.subtle.deriveKey(
|
||||
{
|
||||
name: 'PBKDF2',
|
||||
name: "PBKDF2",
|
||||
salt: saltArray,
|
||||
iterations: ITERATIONS,
|
||||
hash: 'SHA-256'
|
||||
hash: "SHA-256",
|
||||
},
|
||||
keyMaterial,
|
||||
{ name: 'AES-GCM', length: KEY_LENGTH },
|
||||
{ name: "AES-GCM", length: KEY_LENGTH },
|
||||
false,
|
||||
['decrypt']
|
||||
["decrypt"],
|
||||
);
|
||||
|
||||
// Decrypt the content
|
||||
const decryptedContent = await crypto.subtle.decrypt(
|
||||
{
|
||||
name: 'AES-GCM',
|
||||
iv: ivArray
|
||||
name: "AES-GCM",
|
||||
iv: ivArray,
|
||||
},
|
||||
key,
|
||||
encryptedContent
|
||||
encryptedContent,
|
||||
);
|
||||
|
||||
// Convert the decrypted content back to a string
|
||||
@@ -268,33 +268,33 @@ export async function testEncryptionDecryption() {
|
||||
try {
|
||||
const testMessage = "Hello, this is a test message! 🚀";
|
||||
const testPassword = "myTestPassword123";
|
||||
|
||||
|
||||
console.log("Original message:", testMessage);
|
||||
|
||||
|
||||
// Test encryption
|
||||
console.log("Encrypting...");
|
||||
const encrypted = await encryptMessage(testMessage, testPassword);
|
||||
console.log("Encrypted result:", encrypted);
|
||||
|
||||
|
||||
// Test decryption
|
||||
console.log("Decrypting...");
|
||||
const decrypted = await decryptMessage(encrypted, testPassword);
|
||||
console.log("Decrypted result:", decrypted);
|
||||
|
||||
|
||||
// Verify
|
||||
const success = testMessage === decrypted;
|
||||
console.log("Test " + (success ? "PASSED ✅" : "FAILED ❌"));
|
||||
console.log("Messages match:", success);
|
||||
|
||||
|
||||
// Test with wrong password
|
||||
console.log("\nTesting with wrong password...");
|
||||
try {
|
||||
const wrongDecrypted = await decryptMessage(encrypted, "wrongPassword");
|
||||
await decryptMessage(encrypted, "wrongPassword");
|
||||
console.log("Should not reach here");
|
||||
} catch (error) {
|
||||
console.log("Correctly failed with wrong password ✅");
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
} catch (error) {
|
||||
console.error("Test failed with error:", error);
|
||||
|
||||
@@ -680,6 +680,7 @@ export async function setPlanInCache(
|
||||
* @param error that is thrown from an Endorser server call by Axios
|
||||
* @returns user-friendly message, or undefined if none found
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function serverMessageForUser(error: any) {
|
||||
return (
|
||||
// this is how most user messages are returned
|
||||
|
||||
Reference in New Issue
Block a user