fix: treat kind 0 and 3 as replaceable events

This commit is contained in:
Ricardo Arturo Cabral Mejia 2022-11-08 19:43:52 -05:00
parent 55e47a22b1
commit 7a615a99be
No known key found for this signature in database
GPG Key ID: 5931EBF43A650245
3 changed files with 15 additions and 3 deletions

View File

@ -6,6 +6,10 @@ export enum EventKinds {
ENCRYPTED_DIRECT_MESSAGE = 4,
DELETE = 5,
REACTION = 7,
REPLACEABLE_FIRST = 10000,
REPLACEABLE_LAST = 19999,
EPHEMERAL_FIRST = 20000,
EPHEMERAL_LAST = 29999,
}
export enum EventTags {

View File

@ -167,7 +167,7 @@ export const isEventSignatureValid = async (event: Event): Promise<boolean> => {
}
export const isReplaceableEvent = (event: Event): boolean => {
return event.kind >= 10000 && event.kind < 20000
return event.kind === 0 || event.kind === 3 || (event.kind >= 10000 && event.kind < 20000)
}
export const isEphemeralEvent = (event: Event): boolean => {

View File

@ -318,11 +318,19 @@ describe('NIP-12', () => {
describe('NIP-16', () => {
describe('isReplaceableEvent', () => {
it('returns true if event is replaceable', () => {
expect(isReplaceableEvent({ kind: 10000 } as any)).to.be.true
expect(isReplaceableEvent({ kind: EventKinds.REPLACEABLE_FIRST } as any)).to.be.true
})
it('returns true if event is set_metadata', () => {
expect(isReplaceableEvent({ kind: EventKinds.SET_METADATA } as any)).to.be.true
})
it('returns true if event is contact_list', () => {
expect(isReplaceableEvent({ kind: EventKinds.CONTACT_LIST } as any)).to.be.true
})
it('returns false if event is not replaceable', () => {
expect(isReplaceableEvent({ kind: 20000 } as any)).to.be.false
expect(isReplaceableEvent({ kind: EventKinds.REPLACEABLE_LAST + 1 } as any)).to.be.false
})
})