diff options
| author | Adam Soltys <[email protected]> | 2022-12-24 05:22:50 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-12-24 05:22:50 -0800 |
| commit | 10c20c0c5b130c389680e37e4e4aba8e2abdbf1e (patch) | |
| tree | 6862c7f94c899b3dad177b16698c08abc678eefb /src/lib/nostr.js | |
| parent | e1a34bbc86600c6dfb782ac936030379deb6365a (diff) | |
| download | coinos-ui-10c20c0c5b130c389680e37e4e4aba8e2abdbf1e.tar.gz coinos-ui-10c20c0c5b130c389680e37e4e4aba8e2abdbf1e.zip | |
password prompt and pin fixes
Diffstat (limited to 'src/lib/nostr.js')
| -rw-r--r-- | src/lib/nostr.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/nostr.js b/src/lib/nostr.js new file mode 100644 index 00000000..df63d5d8 --- /dev/null +++ b/src/lib/nostr.js @@ -0,0 +1,30 @@ +import { entropyToMnemonic, mnemonicToSeedSync } from 'bip39'; +import { Buffer } from 'buffer'; +import { bech32m } from 'bech32'; +import { bip32, post, stretch } from '$lib/utils'; +import { calculateId, signId } from 'nostr'; + +const { decode, fromWords } = bech32m; + +export let send = async (event, { cipher, username, salt }, password) => { + 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'); + + mnemonic = entropyToMnemonic(entropy); + seed = mnemonicToSeedSync(mnemonic); + key = bip32.fromSeed(seed); + child = key.derivePath("m/44'/1237'/0'/0/0"); + privkey = child.privateKey; + + event.id = await calculateId(event); + event.sig = await signId(privkey, event.id); + + await post(`/${username}`, { event }); +}; |
