mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
fix validateEvent() signature.
This commit is contained in:
@@ -122,9 +122,7 @@ describe('Event', () => {
|
|||||||
|
|
||||||
test('should return false for a non object event', () => {
|
test('should return false for a non object event', () => {
|
||||||
const nonObjectEvent = ''
|
const nonObjectEvent = ''
|
||||||
|
|
||||||
const isValid = validateEvent(nonObjectEvent)
|
const isValid = validateEvent(nonObjectEvent)
|
||||||
|
|
||||||
expect(isValid).toEqual(false)
|
expect(isValid).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
2
event.ts
2
event.ts
@@ -49,7 +49,7 @@ export function getEventHash(event: UnsignedEvent): string {
|
|||||||
|
|
||||||
const isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object
|
const isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object
|
||||||
|
|
||||||
export function validateEvent(event: UnsignedEvent): boolean {
|
export function validateEvent<T>(event: T): event is T & UnsignedEvent {
|
||||||
if (!isRecord(event)) return false
|
if (!isRecord(event)) return false
|
||||||
if (typeof event.kind !== 'number') return false
|
if (typeof event.kind !== 'number') return false
|
||||||
if (typeof event.content !== 'string') return false
|
if (typeof event.content !== 'string') return false
|
||||||
|
|||||||
Reference in New Issue
Block a user