aboutsummaryrefslogtreecommitdiffstats
path: root/tools/notif-faces-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-17 15:33:46 -0700
committerAdam Soltys <[email protected]>2026-09-17 15:33:46 -0700
commitec3bd3e3155d312d88f0f215b24ab131901b36b1 (patch)
tree249a9cbd7cd5977a3240bb9c8682a32ce9a56626 /tools/notif-faces-test.js
parent2f8794174fd4c441bf6c4b7553b4458cf23631ea (diff)
downloadcoinosv3-ec3bd3e3155d312d88f0f215b24ab131901b36b1.tar.gz
coinosv3-ec3bd3e3155d312d88f0f215b24ab131901b36b1.zip
Feed: the zap tally rides on the action-bar bolt, not the header.
The sats total used to sit up by the timestamp as its own chip; now it is the count on the zap button, like likes and boosts have theirs. Amber once anyone has zapped, breathing while ours is in flight, and shown read-only (no zap handler) on posts you can't zap so the number still reads. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Diffstat (limited to 'tools/notif-faces-test.js')
0 files changed, 0 insertions, 0 deletions
ltys <[email protected]> 2024-02-07 10:46:11 -0800 nostr key import' href='/coinos-ui.git/commit/src/lib/nostr.js?id=72305743d0a252d78b135183d9bfe78ab1118be8'>72305743 ^
e69768ba ^

e69768ba ^

72305743 ^





e69768ba ^


32dacb77 ^
72305743 ^
14f57db2 ^
972d5c4f ^

e69768ba ^
e69768ba ^







72305743 ^
e69768ba ^






972d5c4f ^
32dacb77 ^
9f171d1e ^
d4864038 ^

9f171d1e ^


e69768ba ^


















9f171d1e ^


e69768ba ^



9f171d1e ^

72305743 ^
f7416a62 ^



25673e91 ^
f7416a62 ^


72305743 ^
b61377a1 ^
72305743 ^
f7416a62 ^




72305743 ^
51ec9687 ^
72305743 ^

e69768ba ^
14f57db2 ^
e69768ba ^


72305743 ^
e69768ba ^


0a9850c1 ^
e69768ba ^
73d59b06 ^

ea7d2774 ^
e69768ba ^
ea7d2774 ^

72305743 ^














9f171d1e ^
72305743 ^
ff6ef6d8 ^
32dacb77 ^
ff6ef6d8 ^
e69768ba ^
32dacb77 ^
2fead632 ^
72305743 ^
f2583d6c ^
e69768ba ^
72305743 ^




e69768ba ^




72305743 ^
e69768ba ^













2fead632 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
                                           
                                                    












                                                       
                

               

                     





                           


                                                                    
 
                                                                               
                                                       

                                       
                                      







                                                        
                                               






                                                                                
  
 
                                                              

                                               


                                                 


















                                                          


                                    



                                       

 
                                            



                                     
                                  


     
                                      
 
             




                                                                               
  
 

                                          
                                                   
 


                                                  
                                                                   


                                                           
 
                                              

  
                                      
                                                     

  














                                                   
                                              
                                                          
  
 
                              
                                    
  
 
                               
                                         
                              




                                                            




                                                   
                                                                   













                                                           
  
import { browser } from "$app/environment";
import { hexToUint8Array } from "uint8array-extras";
import { get } from "svelte/store";
import { Buffer } from "buffer";
import { fail, wait, post, stretch } from "$lib/utils";
import {
  decrypted,
  password as pw,
  passwordPrompt,
  pin,
  loginRedirect,
} from "$lib/store";
import { goto, invalidate } from "$app/navigation";
import {
  getPublicKey,
  finalizeEvent,
  getEventHash,
  nip04,
  nip19,
} from "nostr-tools";

import {
  encrypt as nip49encrypt,
  decrypt as nip49decrypt,
} from "nostr-tools/nip49";

import { mnemonicToEntropy, entropyToMnemonic } from "@scure/bip39";
import wordlist from "$lib/english";
import { bech32m } from "@scure/base";

import { generateSeedWords, privateKeyFromSeedWords } from "nostr-tools/nip06";
const { encode, decode, toWords, fromWords } = bech32m;

export let generate = async (user) => {
  if (!get(pin)?.length === 6) return;

  let salt = crypto.getRandomValues(new Uint8Array(16));
  let mnemonic = generateSeedWords();
  let sk = privateKeyFromSeedWords(mnemonic);

  let bytes = new Uint8Array(
    await crypto.subtle.encrypt(
      { name: "AES-GCM", iv: new Uint8Array(16) },
      await stretch(await getPassword(), salt),
      Uint8Array.from(Buffer.from(mnemonicToEntropy(mnemonic, wordlist), "hex"))
    )
  );

  user.pubkey = getPublicKey(sk);
  user.cipher = encode("en", toWords(bytes), 180);
  user.salt = Buffer.from(salt).toString("hex");
};

export let encrypt = async ({ message, recipient, user }) => {
  let sk = await getPrivateKey(user);
  return nip04.encrypt(sk, recipient, message);
};

export let decrypt = async ({ event, user }) => {
  let cache = get(decrypted);
  try {
    let { content, pubkey, id } = event;
    if (cache[id]) return cache[id];
    if (pubkey === user.pubkey) pubkey = event.tags[0][1];

    let message = await nip04.decrypt(
      await getPrivateKey(user),
      pubkey,
      content
    );

    cache[id] = Buffer.from(message).toString("utf8");
    decrypted.set(cache);

    return cache[id];
  } catch (e) {
    // console.log(e);
  }
};

function typedArrayToBuffer(array) {
  return array.buffer.slice(
    array.byteOffset,
    array.byteLength + array.byteOffset
  );
}

export let getPrivateKey = async (user) => {
  let k;
  if (browser) {
    k = localStorage.getItem("nsec");
    if (k) {
      return nip19.decode(k).data;
    }
  }

  let { nsec, username, salt } = user;

  if (nsec) {
    k = nip49decrypt(nsec, await getPassword());
  } else k = hexToUint8Array(privateKeyFromSeedWords(await getMnemonic(user)));

  localStorage.setItem("nsec", nip19.nsecEncode(k));
  return k;
};

export let getMnemonic = async (user) => {
  let { cipher, username, salt } = user;
  let mnemonic, key, seed, entropy, child, privkey;

  entropy = new Uint8Array(
    await crypto.subtle.decrypt(
      { name: "AES-GCM", iv: new Uint8Array(16) },
      await stretch(await getPassword(), Buffer.from(salt, "hex")),
      Uint8Array.from(fromWords(decode(cipher, 180).words))
    )
  );

  return entropyToMnemonic(entropy, wordlist);
};

export let getNsec = async (user) => {
  return nip19.nsecEncode(await getPrivateKey(user));
};

export let setNsec = async (user, nsec) => {
  let { data: sk } = nip19.decode(nsec);
  user.pubkey = getPublicKey(sk);
  user.nsec = await encryptNsec(nsec);
};

export let encryptNsec = async (nsec) => {
  let { type, data } = nip19.decode(nsec);
  if (type === "nsec" && data.length === 32) {
    return nip49encrypt(data, await getPassword());
  } else {
    fail("invalid nsec");
  }
};

export let sign = async ({ event, user }) => {
  event = finalizeEvent(event, await getPrivateKey(user));
};

export let send = (event) => {
  return post("/events", { event });
};

let getPassword = async () => {
  if (!get(pw)) passwordPrompt.set(true);
  await wait(() => !!get(pw));
  return get(pw);
};

export let reEncryptEntropy = async (user, newPassword) => {
  let { cipher, username, salt } = user;

  let mnemonic, key, seed, entropy, child, privkey;
  entropy = Buffer.from(
    await crypto.subtle.decrypt(
      { name: "AES-GCM", iv: new Uint8Array(16) },
      await stretch(await getPassword(), 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);
};