Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Zap on nostr-bot npub through be-BOP #1425 #1443

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/lib/server/locks/nostr-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function initRelayPool() {
if (!event.tags.some((tag) => tag[0] === 'p' && tag[1] === nostrPublicKeyHex)) {
return;
}
if (![Kind.EncryptedDirectMessage, Kind.Text].includes(event.kind)) {
if (![Kind.EncryptedDirectMessage, Kind.Text, Kind.Zap].includes(event.kind)) {
return;
}

Expand Down Expand Up @@ -222,6 +222,34 @@ async function handleNostrNotification(nostrNotification: NostRNotification): Pr
sig: ''
} satisfies Event;
}

if (nostrNotification.kind === Kind.Zap) {
const npub = nostrNotification.dest;

if (!npub) {
return;
}

const receiverPublicKeyHex = nostrToHex(npub);

return {
id: '',
content: await nip04.encrypt(nostrPrivateKeyHex, receiverPublicKeyHex, content),
created_at: getUnixTime(
max([
nostrNotification.minCreatedAt ?? nostrNotification.createdAt,
nostrNotification.createdAt
])
),
pubkey: nostrPublicKeyHex,
tags: [
['p', receiverPublicKeyHex],
['bootikVersion', String(NOSTR_PROTOCOL_VERSION)]
],
kind: Kind.Zap,
sig: ''
} satisfies Event;
}
})();

if (!event) {
Expand Down
13 changes: 13 additions & 0 deletions src/routes/(app)/admin[[hash=admin_hash]]/nostr/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@
</label>
<button class="btn btn-black self-start" type="submit">Send</button>
</form>
<h2 class="text-2xl">Zaps</h2>

<ul>
{#each data.receivedMessages.filter((mes) => mes.kind === 9735) as message}
<li class="break-words">
{#if message.kind === 4}
<span title="Encrypted message">'⚡'</span>
{/if}
<time datetime={message.createdAt.toJSON()}>{message.createdAt.toLocaleString('en-UK')}</time>
| You were zapped | 21 sats
</li>
{/each}
</ul>
<h2 class="text-2xl">Received messages</h2>

<ul>
Expand Down
Loading