You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
59 lines
1.5 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"os" |
|
"time" |
|
|
|
"git.mleku.dev/mleku/nostr/encoders/bech32encoding" |
|
"git.mleku.dev/mleku/nostr/encoders/event" |
|
"git.mleku.dev/mleku/nostr/encoders/kind" |
|
"git.mleku.dev/mleku/nostr/encoders/tag" |
|
"git.mleku.dev/mleku/nostr/interfaces/signer/p8k" |
|
) |
|
|
|
func main() { |
|
// Get NOSTR_PRIVATE_KEY from environment |
|
nsec := os.Getenv("NOSTR_PRIVATE_KEY") |
|
if nsec == "" { |
|
fmt.Fprintf(os.Stderr, "ERROR: NOSTR_PRIVATE_KEY environment variable not set\n") |
|
os.Exit(1) |
|
} |
|
|
|
// Decode nsec to get private key bytes |
|
secretBytes, err := bech32encoding.NsecToBytes([]byte(nsec)) |
|
if err != nil { |
|
fmt.Fprintf(os.Stderr, "ERROR: Failed to decode nsec: %v\n", err) |
|
os.Exit(1) |
|
} |
|
|
|
// Create signer and initialize with private key |
|
signer, err := p8k.New() |
|
if err != nil { |
|
fmt.Fprintf(os.Stderr, "ERROR: Failed to create signer: %v\n", err) |
|
os.Exit(1) |
|
} |
|
if err = signer.InitSec(secretBytes); err != nil { |
|
fmt.Fprintf(os.Stderr, "ERROR: Failed to initialize signer: %v\n", err) |
|
os.Exit(1) |
|
} |
|
|
|
// Create a test event (kind 1 - text note) |
|
ev := event.New() |
|
ev.CreatedAt = time.Now().Unix() |
|
ev.Kind = kind.TextNote.K |
|
ev.Content = []byte("Pre-flight test event for import verification") |
|
ev.Tags = tag.NewS() |
|
|
|
// Sign the event |
|
if err := ev.Sign(signer); err != nil { |
|
fmt.Fprintf(os.Stderr, "ERROR: Failed to sign event: %v\n", err) |
|
os.Exit(1) |
|
} |
|
|
|
// Serialize to JSON |
|
eventJSON := ev.Serialize() |
|
|
|
// Output the JSON event |
|
fmt.Println(string(eventJSON)) |
|
}
|
|
|