Skip to content

Commit

Permalink
incluindo um pow de 10 para cada id de primeiro evento para novos pub…
Browse files Browse the repository at this point in the history
…keys
  • Loading branch information
antonioconselheiro committed Oct 17, 2024
1 parent ad5e569 commit 8fc0da0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/app/pages/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ export class ChatComponent implements OnDestroy, OnInit {
this.findStrangerProxy
.searchStranger(this.you)
.then(stranger => this.startConversation(you, stranger))
.catch(e => console.error(new Date().toLocaleString(), e));
.catch(e => {
console.error(new Date().toLocaleString(), e);
this.strangeIsTyping = false;
this.currentState = ChatState.DISCONNECTED;
this.whoDisconnected = null;
this.stranger = null;

throw e;
});
}

disconnect(): Promise<void> {
Expand Down
10 changes: 5 additions & 5 deletions src/app/shared/nostr/nostr-event.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ export class NostrEventFactory {
};

if (includePow) {
eventTemplate = await new Promise<EventTemplate>(resolve => {
const { data: eventSigner } = await new Promise<{ data: EventTemplate }>(resolve => {
const worker = new Worker(new URL('../../workers/nostr-event-pow.worker', import.meta.url));
const channel = new MessageChannel();
channel.port1.onmessage = event => resolve(event.data)
worker.postMessage({ ...eventTemplate, pubkey: user.pubkey }, [channel.port2]);
worker.onmessage = ({ data }) => resolve(data);
worker.postMessage({ ...eventTemplate, pubkey: user.pubkey });
});
debugger;

eventTemplate = eventSigner;
}

return finalizeEvent(
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/omegle-service/find-stranger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class FindStrangerService {
.then(user => user && resolve(user))
.catch(e => {
console.error(e);
debugger;
throw e;
});

sub.unsubscribe();
Expand Down
6 changes: 3 additions & 3 deletions src/app/workers/nostr-event-pow.worker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// <reference lib="webworker" />

import { getEventHash, UnsignedEvent } from "nostr-tools";
import { getPow, minePow } from "nostr-tools/nip13";
import { UnsignedEvent } from "nostr-tools";
import { minePow } from "nostr-tools/nip13";

// include pow to event, some relays require it for first event of a new pubkey
addEventListener('message', ({ data }) => {
const powEvent = minePow(data as UnsignedEvent, getPow(getEventHash(data)));
const powEvent = minePow(data as UnsignedEvent, 10);
postMessage({ data: powEvent });
});

0 comments on commit 8fc0da0

Please sign in to comment.