Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cnixbtc/NostrKit
A simple Swift library providing data types for interacting with Nostr relays.
https://github.com/cnixbtc/NostrKit
ios macos nostr swift
Last synced: 24 days ago
JSON representation
A simple Swift library providing data types for interacting with Nostr relays.
- Host: GitHub
- URL: https://github.com/cnixbtc/NostrKit
- Owner: cnixbtc
- License: mit
- Created: 2022-08-25T14:05:40.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-25T13:49:45.000Z (11 months ago)
- Last Synced: 2024-02-17T05:33:30.849Z (10 months ago)
- Topics: ios, macos, nostr, swift
- Language: Swift
- Homepage: https://github.com/cnixbtc/NostrKit
- Size: 24.4 KB
- Stars: 17
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nostr - NostrKit - a Swift library for interacting with relays (Libraries / Client reviews and/or comparisons)
README
# 🗒 NostrKit
A Swift library providing data types for interacting with a [Nostr](https://github.com/nostr-protocol/nostr) relay.
## Installation
NostrKit is available as a [Swift Package Manager](https://swift.org/package-manager/) package.
To use it, add the following dependency to your `Package.swift` file:``` swift
.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
``` swift
let keyPair = try KeyPair(privateKey: "")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
``` swift
let keyPair = try KeyPair(privateKey: "")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.