mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-30 10:30:44 +02:00
draft nip-34 helpers.
This commit is contained in:
2
event.go
2
event.go
@ -40,6 +40,7 @@ const (
|
||||
KindChannelMessage int = 42
|
||||
KindChannelHideMessage int = 43
|
||||
KindChannelMuteUser int = 44
|
||||
KindPatch int = 1617
|
||||
KindFileMetadata int = 1063
|
||||
KindSimpleGroupAddUser int = 9000
|
||||
KindSimpleGroupRemoveUser int = 9001
|
||||
@ -67,6 +68,7 @@ const (
|
||||
KindProductDefinition int = 30018
|
||||
KindArticle int = 30023
|
||||
KindApplicationSpecificData int = 30078
|
||||
KindRepositoryAnnouncement int = 30617
|
||||
KindSimpleGroupMetadata int = 39000
|
||||
KindSimpleGroupAdmins int = 39001
|
||||
KindSimpleGroupMembers int = 39002
|
||||
|
1
go.mod
1
go.mod
@ -20,6 +20,7 @@ require (
|
||||
require (
|
||||
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
|
||||
github.com/bluekeyes/go-gitdiff v0.7.1 // indirect
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
|
||||
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -3,6 +3,8 @@ github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUq
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
|
||||
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/bluekeyes/go-gitdiff v0.7.1 h1:graP4ElLRshr8ecu0UtqfNTCHrtSyZd3DABQm/DWesQ=
|
||||
github.com/bluekeyes/go-gitdiff v0.7.1/go.mod h1:QpfYYO1E0fTVHVZAZKiRjtSGY9823iCdvGXBcEzHGbM=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
|
||||
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
|
||||
|
1
nip34/nip34.go
Normal file
1
nip34/nip34.go
Normal file
@ -0,0 +1 @@
|
||||
package nip34
|
60
nip34/patch.go
Normal file
60
nip34/patch.go
Normal file
@ -0,0 +1,60 @@
|
||||
package nip34
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/bluekeyes/go-gitdiff/gitdiff"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
)
|
||||
|
||||
type Patch struct {
|
||||
nostr.Event
|
||||
|
||||
Repository nostr.EntityPointer
|
||||
Subject string
|
||||
|
||||
Files []*gitdiff.File
|
||||
Header *gitdiff.PatchHeader
|
||||
}
|
||||
|
||||
func ParsePatch(event nostr.Event) Patch {
|
||||
patch := Patch{
|
||||
Event: event,
|
||||
}
|
||||
|
||||
for _, tag := range event.Tags {
|
||||
if len(tag) < 2 {
|
||||
continue
|
||||
}
|
||||
switch tag[0] {
|
||||
case "a":
|
||||
spl := strings.Split(tag[1], ":")
|
||||
if len(spl) != 3 {
|
||||
continue
|
||||
}
|
||||
if !nostr.IsValid32ByteHex(spl[1]) {
|
||||
continue
|
||||
}
|
||||
patch.Repository.Kind = nostr.KindRepositoryAnnouncement
|
||||
patch.Repository.PublicKey = spl[1]
|
||||
patch.Repository.Identifier = spl[2]
|
||||
if len(tag) >= 3 {
|
||||
patch.Repository.Relays = []string{tag[2]}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
files, preamble, err := gitdiff.Parse(strings.NewReader(event.Content))
|
||||
if err != nil {
|
||||
return patch
|
||||
}
|
||||
patch.Files = files
|
||||
|
||||
header, err := gitdiff.ParsePatchHeader(preamble)
|
||||
if err != nil {
|
||||
return patch
|
||||
}
|
||||
patch.Header = header
|
||||
|
||||
return patch
|
||||
}
|
42
nip34/repository.go
Normal file
42
nip34/repository.go
Normal file
@ -0,0 +1,42 @@
|
||||
package nip34
|
||||
|
||||
import "github.com/nbd-wtf/go-nostr"
|
||||
|
||||
type Repository struct {
|
||||
nostr.Event
|
||||
|
||||
ID string
|
||||
Name string
|
||||
Description string
|
||||
Web []string
|
||||
Clone []string
|
||||
Relays []string
|
||||
}
|
||||
|
||||
func ParseRepository(event nostr.Event) Repository {
|
||||
repo := Repository{
|
||||
Event: event,
|
||||
}
|
||||
|
||||
for _, tag := range event.Tags {
|
||||
if len(tag) < 2 {
|
||||
continue
|
||||
}
|
||||
switch tag[0] {
|
||||
case "d":
|
||||
repo.ID = tag[1]
|
||||
case "name":
|
||||
repo.Name = tag[1]
|
||||
case "description":
|
||||
repo.Description = tag[1]
|
||||
case "web":
|
||||
repo.Web = append(repo.Web, tag[1])
|
||||
case "clone":
|
||||
repo.Clone = append(repo.Clone, tag[1])
|
||||
case "relays":
|
||||
repo.Relays = append(repo.Relays, tag[1])
|
||||
}
|
||||
}
|
||||
|
||||
return repo
|
||||
}
|
Reference in New Issue
Block a user