summaryrefslogtreecommitdiffstats
path: root/kinds.go
blob: cb76e88b6dc0179dd60d5869e0920ed7da61db9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package nostr

// Event kind constants as defined in NIP-01 and related NIPs.
const (
	KindMetadata    = 0
	KindTextNote    = 1
	KindContactList = 3
	KindEncryptedDM = 4
	KindDeletion    = 5
	KindRepost      = 6
	KindReaction    = 7
)

// IsRegular returns true if the kind is a regular event (stored, not replaced).
// Regular events: 1000 <= kind < 10000 or kind in {0,1,2,...} except replaceable ones.
func IsRegular(kind int) bool {
	if kind == KindMetadata || kind == KindContactList {
		return false
	}
	if kind >= 10000 && kind < 20000 {
		return false // replaceable
	}
	if kind >= 20000 && kind < 30000 {
		return false // ephemeral
	}
	if kind >= 30000 && kind < 40000 {
		return false // addressable
	}
	return true
}

// IsReplaceable returns true if the kind is replaceable (NIP-01).
// Replaceable events: 10000 <= kind < 20000, or kind 0 (metadata) or kind 3 (contact list).
func IsReplaceable(kind int) bool {
	if kind == KindMetadata || kind == KindContactList {
		return true
	}
	return kind >= 10000 && kind < 20000
}

// IsEphemeral returns true if the kind is ephemeral (not stored).
// Ephemeral events: 20000 <= kind < 30000.
func IsEphemeral(kind int) bool {
	return kind >= 20000 && kind < 30000
}

// IsAddressable returns true if the kind is addressable (parameterized replaceable).
// Addressable events: 30000 <= kind < 40000.
func IsAddressable(kind int) bool {
	return kind >= 30000 && kind < 40000
}