mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2026-07-22 07:48:27 +00:00
418 lines
18 KiB
TypeScript
418 lines
18 KiB
TypeScript
import { NostrEvent, validateEvent } from './pure.ts'
|
|
|
|
/** Events are **regular**, which means they're all expected to be stored by relays. */
|
|
export function isRegularKind(kind: number): boolean {
|
|
return kind < 10000 && kind !== 0 && kind !== 3
|
|
}
|
|
|
|
/** Events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event is expected to (SHOULD) be stored by relays, older versions are expected to be discarded. */
|
|
export function isReplaceableKind(kind: number): boolean {
|
|
return kind === 0 || kind === 3 || (10000 <= kind && kind < 20000)
|
|
}
|
|
|
|
/** Events are **ephemeral**, which means they are not expected to be stored by relays. */
|
|
export function isEphemeralKind(kind: number): boolean {
|
|
return 20000 <= kind && kind < 30000
|
|
}
|
|
|
|
/** Events are **addressable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag, only the latest event is expected to be stored by relays, older versions are expected to be discarded. */
|
|
export function isAddressableKind(kind: number): boolean {
|
|
return 30000 <= kind && kind < 40000
|
|
}
|
|
|
|
/** Classification of the event kind. */
|
|
export type KindClassification = 'regular' | 'replaceable' | 'ephemeral' | 'parameterized' | 'unknown'
|
|
|
|
/** Determine the classification of this kind of event if known, or `unknown`. */
|
|
export function classifyKind(kind: number): KindClassification {
|
|
if (isRegularKind(kind)) return 'regular'
|
|
if (isReplaceableKind(kind)) return 'replaceable'
|
|
if (isEphemeralKind(kind)) return 'ephemeral'
|
|
if (isAddressableKind(kind)) return 'parameterized'
|
|
return 'unknown'
|
|
}
|
|
|
|
export function isKind<T extends number>(event: unknown, kind: T | Array<T>): event is NostrEvent & { kind: T } {
|
|
const kindAsArray: number[] = kind instanceof Array ? kind : [kind]
|
|
return (validateEvent(event) && kindAsArray.includes(event.kind)) || false
|
|
}
|
|
|
|
export const Metadata = 0
|
|
export type Metadata = typeof Metadata
|
|
export const ShortTextNote = 1
|
|
export type ShortTextNote = typeof ShortTextNote
|
|
export const RecommendRelay = 2
|
|
export type RecommendRelay = typeof RecommendRelay
|
|
export const Contacts = 3
|
|
export type Contacts = typeof Contacts
|
|
export const EncryptedDirectMessage = 4
|
|
export type EncryptedDirectMessage = typeof EncryptedDirectMessage
|
|
export const EventDeletion = 5
|
|
export type EventDeletion = typeof EventDeletion
|
|
export const Repost = 6
|
|
export type Repost = typeof Repost
|
|
export const Reaction = 7
|
|
export type Reaction = typeof Reaction
|
|
export const BadgeAward = 8
|
|
export type BadgeAward = typeof BadgeAward
|
|
export const ChatMessage = 9
|
|
export type ChatMessage = typeof ChatMessage
|
|
export const SimpleGroupThreadedReply = 10
|
|
export type SimpleGroupThreadedReply = typeof SimpleGroupThreadedReply
|
|
export const ForumThread = 11
|
|
export type ForumThread = typeof ForumThread
|
|
export const SimpleGroupReply = 12
|
|
export type SimpleGroupReply = typeof SimpleGroupReply
|
|
export const Seal = 13
|
|
export type Seal = typeof Seal
|
|
export const PrivateDirectMessage = 14
|
|
export type PrivateDirectMessage = typeof PrivateDirectMessage
|
|
export const FileMessage = 15
|
|
export type FileMessage = typeof FileMessage
|
|
export const GenericRepost = 16
|
|
export type GenericRepost = typeof GenericRepost
|
|
export const ReactionToWebsite = 17
|
|
export type ReactionToWebsite = typeof ReactionToWebsite
|
|
export const Photo = 20
|
|
export type Photo = typeof Photo
|
|
export const NormalVideo = 21
|
|
export type NormalVideo = typeof NormalVideo
|
|
export const ShortVideo = 22
|
|
export type ShortVideo = typeof ShortVideo
|
|
export const PublicMessage = 24
|
|
export type PublicMessage = typeof PublicMessage
|
|
export const ChannelCreation = 40
|
|
export type ChannelCreation = typeof ChannelCreation
|
|
export const ChannelMetadata = 41
|
|
export type ChannelMetadata = typeof ChannelMetadata
|
|
export const ChannelMessage = 42
|
|
export type ChannelMessage = typeof ChannelMessage
|
|
export const ChannelHideMessage = 43
|
|
export type ChannelHideMessage = typeof ChannelHideMessage
|
|
export const ChannelMuteUser = 44
|
|
export type ChannelMuteUser = typeof ChannelMuteUser
|
|
export const PodcastEpisode = 54
|
|
export type PodcastEpisode = typeof PodcastEpisode
|
|
export const Chess = 64
|
|
export type Chess = typeof Chess
|
|
export const MergeRequests = 818
|
|
export type MergeRequests = typeof MergeRequests
|
|
export const PollResponse = 1018
|
|
export type PollResponse = typeof PollResponse
|
|
export const Bid = 1021
|
|
export type Bid = typeof Bid
|
|
export const BidConfirmation = 1022
|
|
export type BidConfirmation = typeof BidConfirmation
|
|
export const OpenTimestamps = 1040
|
|
export type OpenTimestamps = typeof OpenTimestamps
|
|
export const GiftWrap = 1059
|
|
export type GiftWrap = typeof GiftWrap
|
|
export const FileMetadata = 1063
|
|
export type FileMetadata = typeof FileMetadata
|
|
export const Poll = 1068
|
|
export type Poll = typeof Poll
|
|
export const Comment = 1111
|
|
export type Comment = typeof Comment
|
|
export const Voice = 1222
|
|
export type Voice = typeof Voice
|
|
export const Scroll = 1227
|
|
export type Scroll = typeof Scroll
|
|
export const VoiceComment = 1244
|
|
export type VoiceComment = typeof VoiceComment
|
|
export const LiveChatMessage = 1311
|
|
export type LiveChatMessage = typeof LiveChatMessage
|
|
export const CodeSnippet = 1337
|
|
export type CodeSnippet = typeof CodeSnippet
|
|
export const Patch = 1617
|
|
export type Patch = typeof Patch
|
|
export const GitPullRequest = 1618
|
|
export type GitPullRequest = typeof GitPullRequest
|
|
export const GitPullRequestUpdate = 1619
|
|
export type GitPullRequestUpdate = typeof GitPullRequestUpdate
|
|
export const Issue = 1621
|
|
export type Issue = typeof Issue
|
|
export const Reply = 1622
|
|
export type Reply = typeof Reply
|
|
export const StatusOpen = 1630
|
|
export type StatusOpen = typeof StatusOpen
|
|
export const StatusApplied = 1631
|
|
export type StatusApplied = typeof StatusApplied
|
|
export const StatusClosed = 1632
|
|
export type StatusClosed = typeof StatusClosed
|
|
export const StatusDraft = 1633
|
|
export type StatusDraft = typeof StatusDraft
|
|
export const ProblemTracker = 1971
|
|
export type ProblemTracker = typeof ProblemTracker
|
|
export const Report = 1984
|
|
export type Report = typeof Report
|
|
export const Reporting = 1984
|
|
export type Reporting = typeof Reporting
|
|
export const Label = 1985
|
|
export type Label = typeof Label
|
|
export const RelayReviews = 1986
|
|
export type RelayReviews = typeof RelayReviews
|
|
export const AIEmbeddings = 1987
|
|
export type AIEmbeddings = typeof AIEmbeddings
|
|
export const Torrent = 2003
|
|
export type Torrent = typeof Torrent
|
|
export const TorrentComment = 2004
|
|
export type TorrentComment = typeof TorrentComment
|
|
export const CoinjoinPool = 2022
|
|
export type CoinjoinPool = typeof CoinjoinPool
|
|
export const DecoupledKeyClientAnnouncement = 4454
|
|
export type DecoupledKeyClientAnnouncement = typeof DecoupledKeyClientAnnouncement
|
|
export const DecoupledEncryptionKeyDistribution = 4455
|
|
export type DecoupledEncryptionKeyDistribution = typeof DecoupledEncryptionKeyDistribution
|
|
export const CommunityPostApproval = 4550
|
|
export type CommunityPostApproval = typeof CommunityPostApproval
|
|
export const JobRequest = 5999
|
|
export type JobRequest = typeof JobRequest
|
|
export const JobResult = 6999
|
|
export type JobResult = typeof JobResult
|
|
export const JobFeedback = 7000
|
|
export type JobFeedback = typeof JobFeedback
|
|
export const ReservedCashuWalletTokens = 7374
|
|
export type ReservedCashuWalletTokens = typeof ReservedCashuWalletTokens
|
|
export const CashuWalletTokens = 7375
|
|
export type CashuWalletTokens = typeof CashuWalletTokens
|
|
export const CashuWalletHistory = 7376
|
|
export type CashuWalletHistory = typeof CashuWalletHistory
|
|
export const GeocacheLog = 7516
|
|
export type GeocacheLog = typeof GeocacheLog
|
|
export const GeocacheProofOfFind = 7517
|
|
export type GeocacheProofOfFind = typeof GeocacheProofOfFind
|
|
export const SimpleGroupPutUser = 9000
|
|
export type SimpleGroupPutUser = typeof SimpleGroupPutUser
|
|
export const SimpleGroupRemoveUser = 9001
|
|
export type SimpleGroupRemoveUser = typeof SimpleGroupRemoveUser
|
|
export const SimpleGroupEditMetadata = 9002
|
|
export type SimpleGroupEditMetadata = typeof SimpleGroupEditMetadata
|
|
export const SimpleGroupDeleteEvent = 9005
|
|
export type SimpleGroupDeleteEvent = typeof SimpleGroupDeleteEvent
|
|
export const SimpleGroupCreateGroup = 9007
|
|
export type SimpleGroupCreateGroup = typeof SimpleGroupCreateGroup
|
|
export const SimpleGroupDeleteGroup = 9008
|
|
export type SimpleGroupDeleteGroup = typeof SimpleGroupDeleteGroup
|
|
export const SimpleGroupCreateInvite = 9009
|
|
export type SimpleGroupCreateInvite = typeof SimpleGroupCreateInvite
|
|
export const SimpleGroupJoinRequest = 9021
|
|
export type SimpleGroupJoinRequest = typeof SimpleGroupJoinRequest
|
|
export const SimpleGroupLeaveRequest = 9022
|
|
export type SimpleGroupLeaveRequest = typeof SimpleGroupLeaveRequest
|
|
export const ZapGoal = 9041
|
|
export type ZapGoal = typeof ZapGoal
|
|
export const NutZap = 9321
|
|
export type NutZap = typeof NutZap
|
|
export const TidalLogin = 9467
|
|
export type TidalLogin = typeof TidalLogin
|
|
export const ZapRequest = 9734
|
|
export type ZapRequest = typeof ZapRequest
|
|
export const Zap = 9735
|
|
export type Zap = typeof Zap
|
|
export const Highlights = 9802
|
|
export type Highlights = typeof Highlights
|
|
export const Mutelist = 10000
|
|
export type Mutelist = typeof Mutelist
|
|
export const Pinlist = 10001
|
|
export type Pinlist = typeof Pinlist
|
|
export const RelayList = 10002
|
|
export type RelayList = typeof RelayList
|
|
export const BookmarkList = 10003
|
|
export type BookmarkList = typeof BookmarkList
|
|
export const CommunitiesList = 10004
|
|
export type CommunitiesList = typeof CommunitiesList
|
|
export const PublicChatsList = 10005
|
|
export type PublicChatsList = typeof PublicChatsList
|
|
export const BlockedRelaysList = 10006
|
|
export type BlockedRelaysList = typeof BlockedRelaysList
|
|
export const SearchRelaysList = 10007
|
|
export type SearchRelaysList = typeof SearchRelaysList
|
|
export const SimpleGroupList = 10009
|
|
export type SimpleGroupList = typeof SimpleGroupList
|
|
export const FavoriteRelays = 10012
|
|
export type FavoriteRelays = typeof FavoriteRelays
|
|
export const PrivateEventRelayList = 10013
|
|
export type PrivateEventRelayList = typeof PrivateEventRelayList
|
|
export const InterestsList = 10015
|
|
export type InterestsList = typeof InterestsList
|
|
export const NutZapInfo = 10019
|
|
export type NutZapInfo = typeof NutZapInfo
|
|
export const MediaFollows = 10020
|
|
export type MediaFollows = typeof MediaFollows
|
|
export const FavoriteFollowSets = 10021
|
|
export type FavoriteFollowSets = typeof FavoriteFollowSets
|
|
export const UserEmojiList = 10030
|
|
export type UserEmojiList = typeof UserEmojiList
|
|
export const DecoupledKeyAnnouncement = 10044
|
|
export type DecoupledKeyAnnouncement = typeof DecoupledKeyAnnouncement
|
|
export const DirectMessageRelaysList = 10050
|
|
export type DirectMessageRelaysList = typeof DirectMessageRelaysList
|
|
export const FavoritePodcasts = 10054
|
|
export type FavoritePodcasts = typeof FavoritePodcasts
|
|
export const BlossomServerList = 10063
|
|
export type BlossomServerList = typeof BlossomServerList
|
|
export const FileServerPreference = 10096
|
|
export type FileServerPreference = typeof FileServerPreference
|
|
export const GoodWikiAuthorList = 10101
|
|
export type GoodWikiAuthorList = typeof GoodWikiAuthorList
|
|
export const GoodWikiRelayList = 10102
|
|
export type GoodWikiRelayList = typeof GoodWikiRelayList
|
|
export const PodcastMetadata = 10154
|
|
export type PodcastMetadata = typeof PodcastMetadata
|
|
export const AuthoredPodcasts = 10164
|
|
export type AuthoredPodcasts = typeof AuthoredPodcasts
|
|
export const RelayMonitorAnnouncement = 10166
|
|
export type RelayMonitorAnnouncement = typeof RelayMonitorAnnouncement
|
|
export const RoomPresence = 10312
|
|
export type RoomPresence = typeof RoomPresence
|
|
export const UserGraspList = 10317
|
|
export type UserGraspList = typeof UserGraspList
|
|
export const ProxyAnnouncement = 10377
|
|
export type ProxyAnnouncement = typeof ProxyAnnouncement
|
|
export const TransportMethodAnnouncement = 11111
|
|
export type TransportMethodAnnouncement = typeof TransportMethodAnnouncement
|
|
export const NWCWalletInfo = 13194
|
|
export type NWCWalletInfo = typeof NWCWalletInfo
|
|
export const NsiteRoot = 15128
|
|
export type NsiteRoot = typeof NsiteRoot
|
|
export const CashuWalletEvent = 17375
|
|
export type CashuWalletEvent = typeof CashuWalletEvent
|
|
export const LightningPubRPC = 21000
|
|
export type LightningPubRPC = typeof LightningPubRPC
|
|
export const ClientAuth = 22242
|
|
export type ClientAuth = typeof ClientAuth
|
|
export const NWCWalletRequest = 23194
|
|
export type NWCWalletRequest = typeof NWCWalletRequest
|
|
export const NWCWalletResponse = 23195
|
|
export type NWCWalletResponse = typeof NWCWalletResponse
|
|
export const NostrConnect = 24133
|
|
export type NostrConnect = typeof NostrConnect
|
|
export const BlobsAuth = 24242
|
|
export type BlobsAuth = typeof BlobsAuth
|
|
export const HTTPAuth = 27235
|
|
export type HTTPAuth = typeof HTTPAuth
|
|
export const Followsets = 30000
|
|
export type Followsets = typeof Followsets
|
|
export const Genericlists = 30001
|
|
export type Genericlists = typeof Genericlists
|
|
export const Relaysets = 30002
|
|
export type Relaysets = typeof Relaysets
|
|
export const Bookmarksets = 30003
|
|
export type Bookmarksets = typeof Bookmarksets
|
|
export const Curationsets = 30004
|
|
export type Curationsets = typeof Curationsets
|
|
export const CuratedVideoSets = 30005
|
|
export type CuratedVideoSets = typeof CuratedVideoSets
|
|
export const MuteSets = 30007
|
|
export type MuteSets = typeof MuteSets
|
|
export const ProfileBadges = 30008
|
|
export type ProfileBadges = typeof ProfileBadges
|
|
export const BadgeDefinition = 30009
|
|
export type BadgeDefinition = typeof BadgeDefinition
|
|
export const Interestsets = 30015
|
|
export type Interestsets = typeof Interestsets
|
|
export const CreateOrUpdateStall = 30017
|
|
export type CreateOrUpdateStall = typeof CreateOrUpdateStall
|
|
export const CreateOrUpdateProduct = 30018
|
|
export type CreateOrUpdateProduct = typeof CreateOrUpdateProduct
|
|
export const MarketplaceUI = 30019
|
|
export type MarketplaceUI = typeof MarketplaceUI
|
|
export const ProductSoldAsAuction = 30020
|
|
export type ProductSoldAsAuction = typeof ProductSoldAsAuction
|
|
export const LongFormArticle = 30023
|
|
export type LongFormArticle = typeof LongFormArticle
|
|
export const DraftLong = 30024
|
|
export type DraftLong = typeof DraftLong
|
|
export const Emojisets = 30030
|
|
export type Emojisets = typeof Emojisets
|
|
export const ModularArticleHeader = 30040
|
|
export type ModularArticleHeader = typeof ModularArticleHeader
|
|
export const ModularArticleContent = 30041
|
|
export type ModularArticleContent = typeof ModularArticleContent
|
|
export const ReleaseArtifactSets = 30063
|
|
export type ReleaseArtifactSets = typeof ReleaseArtifactSets
|
|
export const Application = 30078
|
|
export type Application = typeof Application
|
|
export const RelayDiscovery = 30166
|
|
export type RelayDiscovery = typeof RelayDiscovery
|
|
export const AppCurationSet = 30267
|
|
export type AppCurationSet = typeof AppCurationSet
|
|
export const LiveEvent = 30311
|
|
export type LiveEvent = typeof LiveEvent
|
|
export const InteractiveRoom = 30312
|
|
export type InteractiveRoom = typeof InteractiveRoom
|
|
export const ConferenceEvent = 30313
|
|
export type ConferenceEvent = typeof ConferenceEvent
|
|
export const UserStatuses = 30315
|
|
export type UserStatuses = typeof UserStatuses
|
|
export const SlideSet = 30388
|
|
export type SlideSet = typeof SlideSet
|
|
export const ClassifiedListing = 30402
|
|
export type ClassifiedListing = typeof ClassifiedListing
|
|
export const DraftClassifiedListing = 30403
|
|
export type DraftClassifiedListing = typeof DraftClassifiedListing
|
|
export const RepositoryAnnouncement = 30617
|
|
export type RepositoryAnnouncement = typeof RepositoryAnnouncement
|
|
export const RepositoryState = 30618
|
|
export type RepositoryState = typeof RepositoryState
|
|
export const WikiArticle = 30818
|
|
export type WikiArticle = typeof WikiArticle
|
|
export const Redirects = 30819
|
|
export type Redirects = typeof Redirects
|
|
export const DraftEvent = 31234
|
|
export type DraftEvent = typeof DraftEvent
|
|
export const LinkSet = 31388
|
|
export type LinkSet = typeof LinkSet
|
|
export const Feed = 31890
|
|
export type Feed = typeof Feed
|
|
export const Date = 31922
|
|
export type Date = typeof Date
|
|
export const Time = 31923
|
|
export type Time = typeof Time
|
|
export const Calendar = 31924
|
|
export type Calendar = typeof Calendar
|
|
export const CalendarEventRSVP = 31925
|
|
export type CalendarEventRSVP = typeof CalendarEventRSVP
|
|
export const RelayReview = 31987
|
|
export type RelayReview = typeof RelayReview
|
|
export const Handlerrecommendation = 31989
|
|
export type Handlerrecommendation = typeof Handlerrecommendation
|
|
export const Handlerinformation = 31990
|
|
export type Handlerinformation = typeof Handlerinformation
|
|
export const SoftwareApplication = 32267
|
|
export type SoftwareApplication = typeof SoftwareApplication
|
|
export const LegacyNsiteFile = 34128
|
|
export type LegacyNsiteFile = typeof LegacyNsiteFile
|
|
export const VideoViewEvent = 34237
|
|
export type VideoViewEvent = typeof VideoViewEvent
|
|
export const CommunityDefinition = 34550
|
|
export type CommunityDefinition = typeof CommunityDefinition
|
|
export const NsiteNamed = 35128
|
|
export type NsiteNamed = typeof NsiteNamed
|
|
export const GeocacheListing = 37515
|
|
export type GeocacheListing = typeof GeocacheListing
|
|
export const GeocacheLogEntry = 37516
|
|
export type GeocacheLogEntry = typeof GeocacheLogEntry
|
|
export const CashuMintAnnouncement = 38172
|
|
export type CashuMintAnnouncement = typeof CashuMintAnnouncement
|
|
export const FedimintAnnouncement = 38173
|
|
export type FedimintAnnouncement = typeof FedimintAnnouncement
|
|
export const PeerToPeerOrderEvents = 38383
|
|
export type PeerToPeerOrderEvents = typeof PeerToPeerOrderEvents
|
|
export const GroupMetadata = 39000
|
|
export type GroupMetadata = typeof GroupMetadata
|
|
export const SimpleGroupAdmins = 39001
|
|
export type SimpleGroupAdmins = typeof SimpleGroupAdmins
|
|
export const SimpleGroupMembers = 39002
|
|
export type SimpleGroupMembers = typeof SimpleGroupMembers
|
|
export const SimpleGroupRoles = 39003
|
|
export type SimpleGroupRoles = typeof SimpleGroupRoles
|
|
export const SimpleGroupLiveKitParticipants = 39004
|
|
export type SimpleGroupLiveKitParticipants = typeof SimpleGroupLiveKitParticipants
|
|
export const StarterPacks = 39089
|
|
export type StarterPacks = typeof StarterPacks
|
|
export const MediaStarterPacks = 39092
|
|
export type MediaStarterPacks = typeof MediaStarterPacks
|
|
export const WebBookmarks = 39701
|
|
export type WebBookmarks = typeof WebBookmarks
|