implemented event and req

This commit is contained in:
2025-09-02 20:32:53 +01:00
parent 76b251dea9
commit 51f04f5f60
104 changed files with 6368 additions and 125 deletions

View File

@@ -30,9 +30,9 @@ func (ev *E) MarshalBinary(w io.Writer) {
varint.Encode(w, uint64(ev.CreatedAt))
varint.Encode(w, uint64(ev.Kind))
varint.Encode(w, uint64(ev.Tags.Len()))
for _, x := range ev.Tags.ToSliceOfTags() {
for _, x := range *ev.Tags {
varint.Encode(w, uint64(x.Len()))
for _, y := range x.ToSliceOfBytes() {
for _, y := range x.T {
varint.Encode(w, uint64(len(y)))
_, _ = w.Write(y)
}

View File

@@ -5,6 +5,7 @@ import (
"encoders.orly/hex"
"encoders.orly/ints"
"encoders.orly/text"
"lol.mleku.dev/log"
)
// ToCanonical converts the event to the canonical encoding used to derive the
@@ -14,14 +15,15 @@ func (ev *E) ToCanonical(dst []byte) (b []byte) {
b = append(b, "[0,\""...)
b = hex.EncAppend(b, ev.Pubkey)
b = append(b, "\","...)
b = ints.New(ev.CreatedAt).Marshal(nil)
b = ints.New(ev.CreatedAt).Marshal(b)
b = append(b, ',')
b = ints.New(ev.Kind).Marshal(nil)
b = ints.New(ev.Kind).Marshal(b)
b = append(b, ',')
b = ev.Tags.Marshal(b)
b = append(b, ',')
b = text.AppendQuote(b, ev.Content, text.NostrEscape)
b = append(b, ']')
log.D.F("canonical: %s", b)
return
}