package main

import (

"fmt"

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

"io/ioutil"

"log"

)

func main() {

// Generate a new private key

sk = "private key"

// Derive the public key from the private key

pk, _ := nostr.DerivePublicKey(sk)

// Encode the private key into NIP-19 format

nsec, _ := nostr.EncodePrivateKey(sk)

// Encode the public key into NIP-19 format

npub, _ := nostr.EncodePublicKey(pk)

filePath := "path/to/your/file.txt"

// Read the file into a byte slice

content, err := ioutil.ReadFile(filePath)

if err!= nil {

log.Fatalf("Failed to read file: %v", err)

}

// Convert the byte slice to a string

dmcontent := string(content)

// Create a new event to represent the DM

event := &nostr.Event{

Type: "dm",

Payload: map[string]interface{}{

"recipient": npub,

"content": dmcontent,

},

Timestamp: nostr.Now(),

Signature: sk.Sign([]byte(fmt.Sprintf("%s %s", nsec, npub))),

}

// Publish the event to a relay

relayURL := "wss://your-relay-url-here"

err = nostr.Publish(event, relayURL)

if err!= nil {

fmt.Println("Error publishing event:", err)

return

}

fmt.Println("Direct message sent successfully!")

}

Reply to this note

Please Login to reply.

Discussion

No replies yet.