diff --git a/deploy/example.ts b/deploy/example.ts index 526d2ac..0c53da7 100644 --- a/deploy/example.ts +++ b/deploy/example.ts @@ -5,9 +5,7 @@ const relay = await run({ default_policy: { allowed_kinds: "all", }, - default_information: { - auth_required: false, - }, + auth_required: true, }); if (relay instanceof Error) { console.error(relay); diff --git a/main.tsx b/main.ts similarity index 95% rename from main.tsx rename to main.ts index 39723da..abff69c 100644 --- a/main.tsx +++ b/main.ts @@ -79,7 +79,7 @@ export type Relay = { [Symbol.asyncDispose]: () => Promise; }; -const ENV_relayed_pubkey = "relayed_pubkey"; +export const ENV_relayed_pubkey = "relayed_pubkey"; export async function run(args: { port?: number; @@ -107,7 +107,7 @@ export async function run(args: { const write_replaceable_event = write_replaceable_event_sqlite(db); const write_regular_event = write_regular_event_sqlite(db); const get_event_count = get_event_count_sqlite(db); - const get_events_by_filter = get_events_by_filter_sqlite(db); + const get_events_by_filter = get_events_by_filter_sqlite(db, args._debug || false); // Administrator Keys if (args.admin == undefined) { @@ -169,23 +169,7 @@ export async function run(args: { }, root_handler({ ...args, - is_member: ((admin: PublicKey) => async (pubkey: string) => { - const key = PublicKey.FromString(pubkey); - if (key instanceof Error) { - return key; - } - // admin is always a member - if (key.hex == admin.hex) { - return true; - } - const policy = await policyStore.resolvePolicyByKind(NostrKind.TEXT_NOTE); - if (policy instanceof Error) { - return policy; - } - const policyAllow = policy.allow.has(pubkey); - const policyBlock = policy.block.has(pubkey); - return policyAllow && !policyBlock; - })(args.admin), + is_member: is_member({ admin: args.admin, policyStore }), // deletion delete_event: delete_event_sqlite(db), delete_events_from_pubkey: async () => { @@ -483,7 +467,27 @@ async function verifyToken(event: NostrEvent, relayInformationStore: RelayInform } } -// export const kv = await Deno.openKv("./test-kv"); +const is_member = (args: { + admin: PublicKey; + policyStore: PolicyStore; +}): func_IsMember => +async (pubkey: string) => { + const { admin, policyStore } = args; + const key = PublicKey.FromString(pubkey); + if (key instanceof Error) { + return key; + } + if (key.hex == admin.hex) { + return true; + } + const policy = await policyStore.resolvePolicyByKind(NostrKind.TEXT_NOTE); + if (policy instanceof Error) { + return policy; + } + const policyAllow = policy.allow.has(pubkey); + const policyBlock = policy.block.has(pubkey); + return policyAllow && !policyBlock; +}; const graphiql = `