Skip to content

Commit

Permalink
nip18: don't stringify protected event.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsaiToshiya authored and fiatjaf committed Jan 18, 2025
1 parent 3266b4d commit 1e5bfe8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions nip18.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,30 @@ describe('getRepostedEventPointer', () => {
expect(repostedEventPointer!.relays).toEqual([relayUrl])
})
})

describe('finishRepostEvent', () => {
const privateKey = hexToBytes('d217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf')

test('should create an event with empty content if the reposted event is protected', () => {
const repostedEvent = finalizeEvent(
{
kind: ShortTextNote,
tags: [
['e', 'replied event id'],
['p', 'replied event pubkey'],
['-'],
],
content: 'Replied to a post',
created_at: 1617932115,
},
privateKey,
)
const template = {
created_at: 1617932115,
}

const event = finishRepostEvent(template, repostedEvent, relayUrl, privateKey)

expect(event.content).toBe('')
})
})
2 changes: 1 addition & 1 deletion nip18.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function finishRepostEvent(
{
kind: Repost,
tags: [...(t.tags ?? []), ['e', reposted.id, relayUrl], ['p', reposted.pubkey]],
content: t.content === '' ? '' : JSON.stringify(reposted),
content: t.content === '' || reposted.tags?.find(tag => tag[0] === '-') ? '' : JSON.stringify(reposted),
created_at: t.created_at,
},
privateKey,
Expand Down

0 comments on commit 1e5bfe8

Please sign in to comment.