types.go raw
1 package find
2
3 import (
4 "time"
5
6 "next.orly.dev/pkg/nostr/encoders/event"
7 )
8
9 // Event kind constants as defined in the NIP
10 const (
11 KindRegistrationProposal = 30100 // Parameterized replaceable
12 KindAttestation = 20100 // Ephemeral
13 KindTrustGraph = 30101 // Parameterized replaceable
14 KindNameState = 30102 // Parameterized replaceable
15 KindNameRecords = 30103 // Parameterized replaceable
16 KindCertificate = 30104 // Parameterized replaceable
17 KindWitnessService = 30105 // Parameterized replaceable
18 )
19
20 // Action types for registration proposals
21 const (
22 ActionRegister = "register"
23 ActionTransfer = "transfer"
24 )
25
26 // Decision types for attestations
27 const (
28 DecisionApprove = "approve"
29 DecisionReject = "reject"
30 DecisionAbstain = "abstain"
31 )
32
33 // DNS record types
34 const (
35 RecordTypeA = "A"
36 RecordTypeAAAA = "AAAA"
37 RecordTypeCNAME = "CNAME"
38 RecordTypeMX = "MX"
39 RecordTypeTXT = "TXT"
40 RecordTypeNS = "NS"
41 RecordTypeSRV = "SRV"
42 )
43
44 // Time constants
45 const (
46 ProposalExpiry = 5 * time.Minute // Proposals expire after 5 minutes
47 AttestationExpiry = 3 * time.Minute // Attestations expire after 3 minutes
48 TrustGraphExpiry = 30 * 24 * time.Hour // Trust graphs expire after 30 days
49 NameRegistrationPeriod = 365 * 24 * time.Hour // Names expire after 1 year
50 PreferentialRenewalDays = 30 // Final 30 days before expiration
51 CertificateValidity = 90 * 24 * time.Hour // Recommended certificate validity
52 WitnessServiceExpiry = 180 * 24 * time.Hour // Witness service info expires after 180 days
53 )
54
55 // RegistrationProposal represents a kind 30100 event
56 type RegistrationProposal struct {
57 Event *event.E
58 Name string
59 Action string // "register" or "transfer"
60 PrevOwner string // Previous owner pubkey (for transfers)
61 PrevSig string // Signature from previous owner (for transfers)
62 Expiration time.Time
63 }
64
65 // Attestation represents a kind 20100 event
66 type Attestation struct {
67 Event *event.E
68 ProposalID string // Event ID of the proposal being attested
69 Decision string // "approve", "reject", or "abstain"
70 Weight int // Stake/confidence weight (default 100)
71 Reason string // Human-readable justification
72 ServiceURL string // Registry service endpoint
73 Expiration time.Time
74 }
75
76 // TrustEntry represents a single trust relationship
77 type TrustEntry struct {
78 Pubkey string
79 ServiceURL string
80 TrustScore float64 // 0.0 to 1.0
81 }
82
83 // TrustGraphEvent represents a kind 30101 event (renamed to avoid conflict with TrustGraph manager in trust.go)
84 type TrustGraphEvent struct {
85 Event *event.E
86 Entries []TrustEntry
87 Expiration time.Time
88 }
89
90 // NameState represents a kind 30102 event
91 type NameState struct {
92 Event *event.E
93 Name string
94 Owner string // Current owner pubkey
95 RegisteredAt time.Time
96 ProposalID string // Event ID of the registration proposal
97 Attestations int // Number of attestations
98 Confidence float64 // Consensus confidence score (0.0 to 1.0)
99 Expiration time.Time
100 }
101
102 // NameRecord represents a kind 30103 event
103 type NameRecord struct {
104 Event *event.E
105 Name string
106 Type string // A, AAAA, CNAME, MX, TXT, NS, SRV
107 Value string
108 TTL int // Cache TTL in seconds
109 Priority int // For MX and SRV records
110 Weight int // For SRV records
111 Port int // For SRV records
112 }
113
114 // RecordLimits defines per-type record limits
115 var RecordLimits = map[string]int{
116 RecordTypeA: 5,
117 RecordTypeAAAA: 5,
118 RecordTypeCNAME: 1,
119 RecordTypeMX: 5,
120 RecordTypeTXT: 10,
121 RecordTypeNS: 5,
122 RecordTypeSRV: 10,
123 }
124
125 // Certificate represents a kind 30104 event
126 type Certificate struct {
127 Event *event.E
128 Name string
129 CertPubkey string // Public key for the service
130 ValidFrom time.Time
131 ValidUntil time.Time
132 Challenge string // Challenge token for ownership proof
133 ChallengeProof string // Signature over challenge
134 Witnesses []WitnessSignature
135 Algorithm string // e.g., "secp256k1-schnorr"
136 Usage string // e.g., "tls-replacement"
137 }
138
139 // WitnessSignature represents a witness attestation on a certificate
140 type WitnessSignature struct {
141 Pubkey string
142 Signature string
143 }
144
145 // WitnessService represents a kind 30105 event
146 type WitnessService struct {
147 Event *event.E
148 Endpoint string
149 Challenges []string // Supported challenge types: "txt", "http", "event"
150 MaxValidity int // Maximum certificate validity in seconds
151 Fee int // Fee in sats per certificate
152 ReputationID string // Event ID of reputation event
153 Description string
154 Contact string
155 Expiration time.Time
156 }
157
158 // TransferAuthorization represents the message signed for transfer authorization
159 type TransferAuthorization struct {
160 Name string
161 NewOwner string
162 Timestamp time.Time
163 }
164
165 // ChallengeProofMessage represents the message signed for certificate challenge proof
166 type ChallengeProofMessage struct {
167 Challenge string
168 Name string
169 CertPubkey string
170 ValidUntil time.Time
171 }
172
173 // WitnessMessage represents the message signed by witnesses
174 type WitnessMessage struct {
175 CertPubkey string
176 Name string
177 ValidFrom time.Time
178 ValidUntil time.Time
179 Challenge string
180 }
181