Allow non-members to publish zap receipts for members
This commit is contained in:
parent
0e472bc311
commit
0daac33915
5
extras/strfry/deno.json
Normal file
5
extras/strfry/deno.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"imports": {
|
||||||
|
"@nostr/tools": "jsr:@nostr/tools@^2.3.1"
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import type { Policy } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
import type { Policy } from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||||
import { Client } from 'npm:ldapts';
|
import { Client } from 'npm:ldapts';
|
||||||
|
import { nip57 } from '@nostr/tools';
|
||||||
|
|
||||||
interface LdapConfig {
|
interface LdapConfig {
|
||||||
url: string;
|
url: string;
|
||||||
@ -10,9 +11,34 @@ interface LdapConfig {
|
|||||||
|
|
||||||
const ldapPolicy: Policy<LdapConfig> = async (msg, opts) => {
|
const ldapPolicy: Policy<LdapConfig> = async (msg, opts) => {
|
||||||
const client = new Client({ url: opts.url });
|
const client = new Client({ url: opts.url });
|
||||||
const { pubkey, kind, tags } = msg.event;
|
const { kind, tags } = msg.event;
|
||||||
|
let { pubkey } = msg.event;
|
||||||
let out = { id: msg.event.id }
|
let out = { id: msg.event.id }
|
||||||
|
|
||||||
|
// Zap receipt
|
||||||
|
if (kind === 9735) {
|
||||||
|
let invalidRequest = false;
|
||||||
|
const descriptionTag = tags.find(([t, v]) => t === 'description' && v);
|
||||||
|
const invalidZapRequestMsg = 'Zap receipts must contain a valid zap request from a relay member';
|
||||||
|
|
||||||
|
if (typeof descriptionTag === 'undefined') {
|
||||||
|
out['action'] = 'reject';
|
||||||
|
out['msg'] = invalidZapRequestMsg;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
const zapRequestJSON = descriptionTag[1];
|
||||||
|
const validationResult = nip57.validateZapRequest(zapRequestJSON);
|
||||||
|
|
||||||
|
if (validationResult === null) {
|
||||||
|
pubkey = JSON.parse(zapRequestJSON).pubkey;
|
||||||
|
} else {
|
||||||
|
out['action'] = 'reject';
|
||||||
|
out['msg'] = invalidZapRequestMsg;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.bind(opts.bindDN, opts.password);
|
await client.bind(opts.bindDN, opts.password);
|
||||||
|
|
||||||
@ -20,14 +46,9 @@ const ldapPolicy: Policy<LdapConfig> = async (msg, opts) => {
|
|||||||
filter: `(nostrKey=${pubkey})`,
|
filter: `(nostrKey=${pubkey})`,
|
||||||
attributes: ['nostrKey']
|
attributes: ['nostrKey']
|
||||||
});
|
});
|
||||||
|
|
||||||
const memberKey = searchEntries[0]?.nostrKey;
|
const memberKey = searchEntries[0]?.nostrKey;
|
||||||
|
|
||||||
const accepted = (memberKey === pubkey);
|
if (memberKey === pubkey) {
|
||||||
// TODO if kind is 9735, check that "description" tag contains valid 9734 event,
|
|
||||||
// signed by memberKey and with "p" tag being the same as pubkey (receipt sender)
|
|
||||||
|
|
||||||
if (accepted) {
|
|
||||||
out['action'] = 'accept';
|
out['action'] = 'accept';
|
||||||
out['msg'] = '';
|
out['msg'] = '';
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user