Swiftpack.co - cnixbtc/NostrKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by cnixbtc.
cnixbtc/NostrKit v1.0.0
A simple Swift library providing data types for interacting with Nostr relays.
⭐️ 17
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/cnixbtc/NostrKit.git", from: "v1.0.0")

🗒 NostrKit

A Swift library providing data types for interacting with a Nostr relay.

Installation

NostrKit is available as a Swift Package Manager package. To use it, add the following dependency to your Package.swift file:

.package(url: "https://github.com/cnixbtc/NostrKit.git", from: "1.0.0"),

Functionality

NostrKit provides the necessary data types for interacting with a Nostr relay to create events and manage subscriptions.

Subscribing to Events

let keyPair = try KeyPair(privateKey: "<hex>")

let subscription = Subscription(filters: [
    .init(authors: [keyPair.publicKey])
])

let subscribeMessage = try ClientMessage
    .subscribe(subscription)
    .string()

// Subscribe to events created by this key pair by sending `subscribeMessage` 
// to a relay using a web socket connection of your choice. 
// Later on, create a message to unsubscribe like so:

let unsubscribeMessage = try ClientMessage
    .unsubscribe(subscription.id)
    .string()

Publishing Events

let keyPair = try KeyPair(privateKey: "<hex>")

let event = try Event(keyPair: keyPair, content: "Hello NostrKit.")

let message = ClientMessage
    .event(event)
    .string()

// Publish the event by sending `subscribeMessage` 
// to a relay using a web socket connection of your choice. 

Fully functional code examples can be found in Sources/ExampleReader as well as Sources/ExampleWriter. Run swift run example-reader and swift run example-writer to see them in action.

GitHub

link
Stars: 17
Last commit: 12 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Dependencies

Release Notes

v1.0.0
1 year ago
  • Breaking: Removes Relay type to enforce that users handle socket connections themselves. We want to focus purely on Nostr specific data types.
  • Breaking: Changes EventFilter to explicitly have eventTags and pubKeyTags properties instead of a generic dictionary.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics