Skip to content

Commit

Permalink
Update RelayInfo to reflect current NIP-11 specification (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiu authored Nov 26, 2024
1 parent 1bc7913 commit 32d56c8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
16 changes: 14 additions & 2 deletions Sources/NostrSDK/RelayInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import Foundation
public struct RelayInfo: Codable {
public let name: String?
public let description: String?
public let bannerURL: String?
public let iconURL: String?
public let contactPubkey: String?
public let alternativeContact: String?
public let supportedNIPs: [Int]?
Expand All @@ -26,9 +28,11 @@ public struct RelayInfo: Codable {
public let tags: [String]?
public let postingPolicyURL: String?
public let retentionPolicies: [EventRetentionPolicy]?

enum CodingKeys: String, CodingKey {
case name, description
case bannerURL = "banner"
case iconURL = "icon"
case contactPubkey = "pubkey"
case alternativeContact = "contact"
case supportedNIPs = "supported_nips"
Expand All @@ -49,25 +53,33 @@ public struct RelayInfo: Codable {
public let maxFilters: Int?
public let maxLimit: Int?
public let maxSubscriptionIdLength: Int?
@available(*, deprecated, message: "min_prefix was removed from NIP-11.")
public let minPrefix: Int?
public let maxEventTags: Int?
public let maxContentLength: Int?
public let minProofOfWorkDifficulty: Int?
public let isAuthenticationRequired: Bool?
public let isPaymentRequired: Bool?

public let isWriteRestricted: Bool?
public let createdAtLowerLimit: Int64?
public let createdAtUpperLimit: Int64?

enum CodingKeys: String, CodingKey {
case maxMessageLength = "max_message_length"
case maxSubscriptions = "max_subscriptions"
case maxFilters = "max_filters"
case maxLimit = "max_limit"
case maxSubscriptionIdLength = "max_subid_length"
@available(*, deprecated, message: "min_prefix was removed from NIP-11.")
case minPrefix = "min_prefix"
case maxEventTags = "max_event_tags"
case maxContentLength = "max_content_length"
case minProofOfWorkDifficulty = "min_pow_difficulty"
case isAuthenticationRequired = "auth_required"
case isPaymentRequired = "payment_required"
case isWriteRestricted = "restricted_writes"
case createdAtLowerLimit = "created_at_lower_limit"
case createdAtUpperLimit = "created_at_upper_limit"
}
}

Expand Down
7 changes: 6 additions & 1 deletion Tests/NostrSDKTests/Fixtures/relay_info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "nostr.test",
"description": "Nostr Test",
"banner": "https://nostrsdk.com/banner.png",
"icon": "https://nostrsdk.com/icon.png",
"pubkey": "test-pubkey",
"contact": "mailto:[email protected]",
"supported_nips": [
Expand All @@ -25,7 +27,10 @@
"max_content_length": 65536,
"min_pow_difficulty": 0,
"auth_required": false,
"payment_required": true
"payment_required": true,
"restricted_writes": true,
"created_at_lower_limit": 31536000,
"created_at_upper_limit": 3
},
"retention": [
{ "kinds": [0, 1, [5, 7], [40, 49]], "time": 3600 },
Expand Down
7 changes: 6 additions & 1 deletion Tests/NostrSDKTests/RelayInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ final class RelayInfoTests: XCTestCase, FixtureLoading {

XCTAssertEqual(info.name, "nostr.test")
XCTAssertEqual(info.description, "Nostr Test")
XCTAssertEqual(info.bannerURL, "https://nostrsdk.com/banner.png")
XCTAssertEqual(info.iconURL, "https://nostrsdk.com/icon.png")
XCTAssertEqual(info.contactPubkey, "test-pubkey")
XCTAssertEqual(info.alternativeContact, "mailto:[email protected]")
XCTAssertEqual(info.supportedNIPs, [1, 2, 4, 9])
Expand All @@ -37,7 +39,10 @@ final class RelayInfoTests: XCTestCase, FixtureLoading {
XCTAssertEqual(info.limitations?.minProofOfWorkDifficulty, 0)
XCTAssertEqual(info.limitations?.isAuthenticationRequired, false)
XCTAssertEqual(info.limitations?.isPaymentRequired, true)

XCTAssertEqual(info.limitations?.isWriteRestricted, true)
XCTAssertEqual(info.limitations?.createdAtLowerLimit, 31536000)
XCTAssertEqual(info.limitations?.createdAtUpperLimit, 3)

let admissionFee = try XCTUnwrap(info.fees?.admission?.first)
XCTAssertEqual(admissionFee.amount, 1000000)
XCTAssertEqual(admissionFee.unit, "msats")
Expand Down

0 comments on commit 32d56c8

Please sign in to comment.