Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ WHITELISTED_NPUBS_FILE="whitelisted_npubs.json"
BLACKLISTED_NPUBS_FILE="blacklisted_npubs.json"

## LOGGING
HAVEN_LOG_LEVEL="INFO" # DEBUG, INFO, WARNING or ERROR
HAVEN_LOG_LEVEL="INFO" # DEBUG, INFO, WARNING or ERROR

## PROXY / TOR (Optional)
# Set a SOCKS5 proxy URL to route all outgoing connections (e.g., Tor daemon)
PROXY_URL=""
2 changes: 1 addition & 1 deletion blastr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log/slog"
"time"

"github.com/nbd-wtf/go-nostr"
"fiatjaf.com/nostr"
)

func blast(ctx context.Context, ev *nostr.Event) {
Expand Down
17 changes: 7 additions & 10 deletions blossomMigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@ import (
"context"
"log/slog"

"github.com/fiatjaf/khatru/blossom"
"fiatjaf.com/nostr/khatru/blossom"
nipb0blossom "fiatjaf.com/nostr/nipb0/blossom"
"fiatjaf.com/nostr"
)

func migrateBlossomMetadata(ctx context.Context, bl *blossom.BlossomServer) {
// Create a temporary Blossom dbWrapper for the migration
outboxDBWrapper := blossom.EventStoreBlobIndexWrapper{Store: outboxDB, ServiceURL: getHTTPScheme(config.RelayURL) + config.RelayURL}

// List all BlobDescriptor for the relay owner pubkey
ownerPubkey := nPubToPubkey("OWNER_NPUB", config.OwnerNpub)
blobsChan, err := outboxDBWrapper.List(ctx, ownerPubkey)
if err != nil {
slog.Error("🚫 Failed to list blobs", "error", err)
return
}
var blobs []blossom.BlobDescriptor
for blob := range blobsChan {
ownerPubkey := nostr.MustPubKeyFromHex(config.OwnerPubKey)
var blobs []nipb0blossom.BlobDescriptor
for blob := range outboxDBWrapper.List(ctx, ownerPubkey) {
blobs = append(blobs, blob)
}

Expand All @@ -29,7 +26,7 @@ func migrateBlossomMetadata(ctx context.Context, bl *blossom.BlossomServer) {
}

// Create a map to track migrated blobs
migrated := make(map[string]blossom.BlobDescriptor, len(blobs))
migrated := make(map[string]nipb0blossom.BlobDescriptor, len(blobs))

slog.Info("BlobDescriptors will be migrated from Outbox to Blossom's DB", "count", len(blobs))

Expand Down
23 changes: 16 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"time"

"github.com/joho/godotenv"
"github.com/nbd-wtf/go-nostr/nip19"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/nip19"
)

type S3Config struct {
Expand Down Expand Up @@ -66,6 +67,7 @@ type Config struct {
LogLevel string `json:"log_level"`
BlastrRelays []string `json:"blastr_relays"`
BlastrTimeoutSeconds int `json:"blastr_timeout_seconds"`
ProxyURL string `json:"proxy_url"`
S3Config *S3Config `json:"s3_config"`
}

Expand Down Expand Up @@ -118,6 +120,7 @@ func loadConfig() Config {
LogLevel: getEnvString("HAVEN_LOG_LEVEL", "INFO"),
BlastrRelays: getRelayListFromFile(getEnv("BLASTR_RELAYS_FILE")),
BlastrTimeoutSeconds: getEnvInt("BLASTR_TIMEOUT_SECONDS", 5),
ProxyURL: getEnvString("PROXY_URL", ""),
S3Config: getS3Config(),
}

Expand Down Expand Up @@ -166,7 +169,11 @@ func getRelayListFromFile(filePath string) []string {
for i, relay := range relayList {
relay = strings.TrimSpace(relay)
if !strings.HasPrefix(relay, "wss://") && !strings.HasPrefix(relay, "ws://") {
relay = "wss://" + relay
if strings.Contains(relay, ".onion") {
relay = "ws://" + relay
} else {
relay = "wss://" + relay
}
}
relayList[i] = relay
}
Expand Down Expand Up @@ -261,8 +268,6 @@ func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
func nPubToPubkey(label, nPub string) string {
prefix, v, err := nip19.Decode(nPub)
if err != nil {
// Only echo the raw value when it looks like an npub; a malformed
// non-npub (e.g. a mistyped nsec) must not be leaked into logs.
if strings.HasPrefix(nPub, "npub1") {
log.Fatalf("invalid npub for %s: %q could not be decoded (%v)", label, nPub, err)
}
Expand All @@ -271,11 +276,15 @@ func nPubToPubkey(label, nPub string) string {
if prefix != "npub" {
log.Fatalf("invalid npub for %s: expected an npub, got a %q", label, prefix)
}
pubkey, ok := v.(string)
if !ok {
switch value := v.(type) {
case string:
return value
case nostr.PubKey:
return value.Hex()
default:
log.Fatalf("invalid npub for %s: %q did not decode to a public key", label, nPub)
return ""
}
return pubkey
}

var art = `
Expand Down
37 changes: 16 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
module github.com/barrydeen/haven

go 1.24.1
go 1.25

require (
github.com/fiatjaf/eventstore v0.17.5
github.com/fiatjaf/khatru v0.19.1
fiatjaf.com/nostr v0.0.0-20260708142249-c591b5592910
github.com/joho/godotenv v1.5.1
github.com/minio/minio-go/v7 v7.0.98
github.com/nbd-wtf/go-nostr v0.52.3
github.com/puzpuzpuz/xsync/v4 v4.4.0
github.com/spf13/afero v1.15.0
golang.org/x/net v0.50.0
)

require (
fiatjaf.com/lib v0.3.2 // indirect
fiatjaf.com/lib v0.3.7 // indirect
github.com/FastFilter/xorfilter v0.2.1 // indirect
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 // indirect
github.com/PowerDNS/lmdb-go v1.9.3 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/bep/debounce v1.2.1 // indirect
github.com/btcsuite/btcd v0.24.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.6 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.0 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/coder/websocket v1.8.14 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/dgraph-io/badger/v4 v4.8.0 // indirect
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/elnosh/gonuts v0.4.2 // indirect
github.com/fasthttp/websocket v1.5.12 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/flatbuffers v25.9.23+incompatible // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -56,23 +52,22 @@ require (
github.com/rs/cors v1.11.1 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/savsgio/gotils v0.0.0-20250924091648-bce9a52d7761 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/templexxx/cpu v0.0.1 // indirect
github.com/templexxx/xhex v0.0.0-20200614015412-aed53437177b // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tinylib/msgp v1.6.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.69.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.23.0 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading