A Swift library providing data types for interacting with a Nostr relay.
NostrKit is available as a Swift Package Manager package.
To use it, add the following dependency to your
.package(url: "https://github.com/cnixbtc/NostrKit.git", from: "1.0.0"),
NostrKit provides the necessary data types for interacting with a Nostr relay to create events and manage subscriptions.
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()
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
swift run example-reader and
swift run example-writer to see them in action.
|Last commit: 3 weeks ago|
Relaytype to enforce that users handle socket connections themselves. We want to focus purely on Nostr specific data types.
EventFilterto explicitly have
pubKeyTagsproperties instead of a generic dictionary.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics