Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement the nostr protocol #2946

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nostr links
github-tijlxyz committed Nov 17, 2024
commit dbf01b3dd9a704c6c4d0aedd9ffa4af8405e08a6
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ require (
github.com/abadojack/whatlanggo v1.0.1
github.com/andybalholm/brotli v1.1.1
github.com/coreos/go-oidc/v3 v3.11.0
github.com/github-tijlxyz/goldmark-nostr v0.0.1
github.com/go-webauthn/webauthn v0.11.2
github.com/gorilla/mux v1.8.1
github.com/lib/pq v1.10.9
@@ -66,6 +67,4 @@ require (
google.golang.org/protobuf v1.34.2 // indirect
)

go 1.23.1

toolchain go1.23.3
go 1.23.3
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/github-tijlxyz/goldmark-nostr v0.0.1 h1:w/GnHJQCCqFUCYHGJzwcPp4usDBIDAZ9q47nW/57NMc=
github.com/github-tijlxyz/goldmark-nostr v0.0.1/go.mod h1:ezZL9+JeyK9T5VQ4EdtBaREOr7hIuWORuzMwS9wRbA8=
github.com/go-jose/go-jose/v4 v4.0.2 h1:R3l3kkBds16bO7ZFAEEcofK0MkrAJt3jlJznWZG0nvk=
github.com/go-jose/go-jose/v4 v4.0.2/go.mod h1:WVf9LFMHh/QVrmqrOfqun0C45tMe3RoiKJMPvgWwLfY=
github.com/go-webauthn/webauthn v0.11.2 h1:Fgx0/wlmkClTKlnOsdOQ+K5HcHDsDcYIvtYmfhEOSUc=
11 changes: 6 additions & 5 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
@@ -136,20 +136,21 @@ func RefreshFeed(store *storage.Storage, user *model.User, originalFeed *model.F
return false
}

func IsItNostr(url string) (bool, *sdk.ProfileMetadata) {
func IsItNostr(candidateUrl string) (bool, *sdk.ProfileMetadata) {
url := candidateUrl
ctx := context.Background()
if NostrSdk == nil {
Initialize()
}

// check for nostr url prefixes
hasNostrPrefix := false
if strings.HasPrefix(url, "nostr://") {
hasNostrPrefix = true
url = url[8:]
} else if strings.HasPrefix(url, "nostr:") {
hasNostrPrefix = true
url = url[6:]
} else {
// only accept nostr: or nostr:// urls for now
return false, nil
}

// check for npub or nprofile
@@ -164,7 +165,7 @@ func IsItNostr(url string) (bool, *sdk.ProfileMetadata) {
}

// only do nip05 check when nostr prefix
if nip05.IsValidIdentifier(url) {
if hasNostrPrefix && nip05.IsValidIdentifier(url) {
profile, err := NostrSdk.FetchProfileFromInput(ctx, url)
if err != nil {
return false, nil
1 change: 0 additions & 1 deletion internal/reader/icon/checker.go
Original file line number Diff line number Diff line change
@@ -92,6 +92,5 @@ func (c *IconChecker) CreateFeedIconIfMissing() {
}

func (c *IconChecker) UpdateOrCreateFeedIcon() {
slog.Info("hleeeeeeeeeello")
c.fetchAndStoreIcon()
}
4 changes: 4 additions & 0 deletions internal/reader/rewrite/rewrite_functions.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import (
nethtml "golang.org/x/net/html"

"github.com/PuerkitoBio/goquery"
nostrGoldmarkExtension "github.com/github-tijlxyz/goldmark-nostr"
"github.com/yuin/goldmark"
goldmarkhtml "github.com/yuin/goldmark/renderer/html"
)
@@ -413,6 +414,9 @@ func addHackerNewsLinksUsing(entryContent, app string) string {
func parseMarkdown(entryContent string) string {
var sb strings.Builder
md := goldmark.New(
goldmark.WithExtensions(
nostrGoldmarkExtension.NewNostr(),
),
goldmark.WithRendererOptions(
goldmarkhtml.WithUnsafe(),
),
6 changes: 6 additions & 0 deletions internal/reader/sanitizer/sanitizer.go
Original file line number Diff line number Diff line change
@@ -178,6 +178,12 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([
continue
}

if tagName == "a" && attribute.Key == "href" && strings.HasPrefix(value, "nostr:") {
attrNames = append(attrNames, attribute.Key)
htmlAttrs = append(htmlAttrs, fmt.Sprintf(`%s="%s"`, attribute.Key, html.EscapeString(value)))
continue
}

if (tagName == "img" || tagName == "source") && attribute.Key == "srcset" {
value = sanitizeSrcsetAttr(baseURL, value)
}