aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/nostr.js38
-rw-r--r--src/lib/utils.js13
2 files changed, 48 insertions, 3 deletions
diff --git a/src/lib/nostr.js b/src/lib/nostr.js
index ae18fbf1..35d843b2 100644
--- a/src/lib/nostr.js
+++ b/src/lib/nostr.js
@@ -131,3 +131,41 @@ export let sign = async ({ event, user }) => {
export let send = (event) => {
return post('/events', { event });
};
+
+export let reEncryptEntropy = async (user, newPassword) => {
+ let { cipher, username, salt } = user;
+ let password = get(pw);
+
+ if (!password) {
+ passwordPrompt.set(true);
+ }
+
+ try {
+ await post('/password', { password });
+ } catch (e) {
+ passwordPrompt.set(true);
+ }
+
+ await wait(() => !!get(pw));
+ password = get(pw);
+
+ let mnemonic, key, seed, entropy, child, privkey;
+ entropy = Buffer.from(
+ await crypto.subtle.decrypt(
+ { name: 'AES-GCM', iv: new Uint8Array(16) },
+ await stretch(password, Buffer.from(salt, 'hex')),
+ Uint8Array.from(fromWords(decode(cipher, 180).words))
+ ),
+ 'hex'
+ ).toString('hex');
+
+ let bytes = new Uint8Array(
+ await crypto.subtle.encrypt(
+ { name: 'AES-GCM', iv: new Uint8Array(16) },
+ await stretch(newPassword, Buffer.from(salt, 'hex')),
+ Uint8Array.from(Buffer.from(entropy, 'hex'))
+ )
+ );
+
+ return encode('en', toWords(bytes), 180);
+};
diff --git a/src/lib/utils.js b/src/lib/utils.js
index d7fba2fc..77ed93bd 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -46,12 +46,12 @@ export const post = (url, body, headers) => {
if (r.ok) return r.text();
let text = await r.text();
- let message;
+ let message;
try {
({ message } = JSON.parse(text));
} catch (e) {}
- if (message) throw new Error(message);
+ if (message) throw new Error(message);
throw new Error(text);
})
.then((body) => {
@@ -83,7 +83,14 @@ export function reverseFormat(val, locale) {
return Number.isNaN(reversedVal) ? 0 : +reversedVal;
}
-export let protectedRoutes = [/customers/, /dashboard/, /settings/, /transactions/, /\/ln\//, /request/];
+export let protectedRoutes = [
+ /customers/,
+ /dashboard/,
+ /settings/,
+ /transactions/,
+ /\/ln\//,
+ /request/
+];
export const success = (m) => {
toast.pop();