aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-12-21 15:48:14 -0800
committerAdam Soltys <[email protected]>2022-12-21 15:48:14 -0800
commit6ae27be919808df935fb140fd56bb6ae010a219b (patch)
treeba9f5d862cc48abf5b49acfdbd32b87216eadba1 /src/lib/utils.js
parent5c0675fa6815a70033c17a9310d0fa1f9c569e92 (diff)
downloadcoinos-ui-6ae27be919808df935fb140fd56bb6ae010a219b.tar.gz
coinos-ui-6ae27be919808df935fb140fd56bb6ae010a219b.zip
add nostr message field to user profile page
Diffstat (limited to 'src/lib/utils.js')
-rw-r--r--src/lib/utils.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/utils.js b/src/lib/utils.js
index f59b6359..14646ad0 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -1,3 +1,5 @@
+import * as ecc from 'tiny-secp256k1';
+import { BIP32Factory } from 'bip32';
import { browser } from '$app/environment';
import { toast } from '@zerodevx/svelte-toast';
import { goto } from '$app/navigation';
@@ -168,3 +170,25 @@ export const wait = async (f, s = 300) => {
if (i >= s) throw new Error('timeout');
return f();
};
+
+export const stretch = async (password, salt) =>
+ crypto.subtle.deriveKey(
+ {
+ name: 'PBKDF2',
+ salt,
+ iterations: 100000,
+ hash: 'SHA-256'
+ },
+ await crypto.subtle.importKey(
+ 'raw',
+ new TextEncoder().encode(password),
+ { name: 'PBKDF2' },
+ false,
+ ['deriveBits', 'deriveKey']
+ ),
+ { name: 'AES-GCM', length: 256 },
+ true,
+ ['encrypt', 'decrypt']
+ );
+
+export const bip32 = await BIP32Factory(ecc);