Formatting

This commit is contained in:
2026-09-05 18:30:35 +02:00
parent 454a9db1d5
commit 4caa075052
133 changed files with 8260 additions and 8181 deletions
+16 -15
View File
@@ -4,36 +4,37 @@
// importing the service module never opens (or even references) a
// WebSocket.
import type {Filter as NostrFilter} from 'nostr-tools/filter'
import type { Filter as NostrFilter } from 'nostr-tools/filter';
import type {NostrEvent} from './protocol'
import type { NostrEvent } from './protocol';
export type {NostrFilter}
export type { NostrFilter };
export type NwcSubscription = {
close: () => void
}
close: () => void;
};
export type NwcTransport = {
publish: (relays: string[], event: NostrEvent) => Promise<void>
publish: (relays: string[], event: NostrEvent) => Promise<void>;
subscribe: (
relays: string[],
filter: NostrFilter,
onEvent: (event: NostrEvent) => void,
) => NwcSubscription
}
) => NwcSubscription;
};
export const defaultNwcTransport = async (): Promise<NwcTransport> => {
const {SimplePool} = await import('nostr-tools/pool')
const pool = new SimplePool()
const { SimplePool } = await import('nostr-tools/pool');
const pool = new SimplePool();
return {
publish: async (relays, event) => {
const results = await Promise.allSettled(pool.publish(relays, event))
const results = await Promise.allSettled(pool.publish(relays, event));
// one honest relay accepting is enough - same rule as the backup
if (!results.some((r) => r.status === 'fulfilled')) {
throw new Error('No relay accepted the event.')
throw new Error('No relay accepted the event.');
}
},
subscribe: (relays, filter, onEvent) => pool.subscribeMany(relays, filter, {onevent: onEvent}),
}
}
subscribe: (relays, filter, onEvent) =>
pool.subscribeMany(relays, filter, { onevent: onEvent }),
};
};