Add verifySignatureWorker
This commit is contained in:
parent
e5d6c44437
commit
bc3f4bc534
|
@ -12,6 +12,7 @@ import { Sub } from '@/subs.ts';
|
|||
import { getTagSet } from '@/tags.ts';
|
||||
import { trends } from '@/trends.ts';
|
||||
import { eventAge, isRelay, nostrDate, Time } from '@/utils.ts';
|
||||
import { verifySignatureWorker } from '@/workers/verify.ts';
|
||||
|
||||
import type { EventData } from '@/types.ts';
|
||||
|
||||
|
@ -20,6 +21,7 @@ import type { EventData } from '@/types.ts';
|
|||
* It is idempotent, so it can be called multiple times for the same event.
|
||||
*/
|
||||
async function handleEvent(event: Event): Promise<void> {
|
||||
if (!(await verifySignatureWorker(event))) return;
|
||||
if (encounterEvent(event)) return;
|
||||
const data = await getEventData(event);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { getActiveRelays } from '@/db/relays.ts';
|
|||
import { type Event, RelayPool } from '@/deps.ts';
|
||||
|
||||
const allRelays = await getActiveRelays();
|
||||
const pool = new RelayPool(allRelays);
|
||||
const pool = new RelayPool(allRelays, { skipVerification: true });
|
||||
|
||||
/** Publish an event to the given relays, or the entire pool. */
|
||||
function publish(event: Event, relays: string[] = allRelays) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import { Comlink, type Event } from '@/deps.ts';
|
||||
|
||||
import type { VerifyWorker } from './verify.worker.ts';
|
||||
|
||||
const worker = Comlink.wrap<typeof VerifyWorker>(
|
||||
new Worker(new URL('./verify.worker.ts', import.meta.url), { type: 'module' }),
|
||||
);
|
||||
|
||||
function verifySignatureWorker<K extends number>(event: Event<K>): Promise<boolean> {
|
||||
return worker.verifySignature(event);
|
||||
}
|
||||
|
||||
export { verifySignatureWorker };
|
|
@ -0,0 +1,9 @@
|
|||
import { Comlink, type Event, type VerifiedEvent, verifySignature } from '@/deps.ts';
|
||||
|
||||
export const VerifyWorker = {
|
||||
verifySignature<K extends number>(event: Event<K>): event is VerifiedEvent<K> {
|
||||
return verifySignature(event);
|
||||
},
|
||||
};
|
||||
|
||||
Comlink.expose(VerifyWorker);
|
Loading…
Reference in New Issue