From 32d56c8fed0f4e83edf3323b5f317afec3d181f1 Mon Sep 17 00:00:00 2001 From: Terry Yiu <963907+tyiu@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:21:31 +0100 Subject: [PATCH] Update RelayInfo to reflect current NIP-11 specification (#201) --- Sources/NostrSDK/RelayInfo.swift | 16 ++++++++++++++-- Tests/NostrSDKTests/Fixtures/relay_info.json | 7 ++++++- Tests/NostrSDKTests/RelayInfoTests.swift | 7 ++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Sources/NostrSDK/RelayInfo.swift b/Sources/NostrSDK/RelayInfo.swift index efc6ae3..3e9e84d 100644 --- a/Sources/NostrSDK/RelayInfo.swift +++ b/Sources/NostrSDK/RelayInfo.swift @@ -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]? @@ -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" @@ -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" } } diff --git a/Tests/NostrSDKTests/Fixtures/relay_info.json b/Tests/NostrSDKTests/Fixtures/relay_info.json index 4137397..296a120 100644 --- a/Tests/NostrSDKTests/Fixtures/relay_info.json +++ b/Tests/NostrSDKTests/Fixtures/relay_info.json @@ -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:somebody@nostr.test", "supported_nips": [ @@ -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 }, diff --git a/Tests/NostrSDKTests/RelayInfoTests.swift b/Tests/NostrSDKTests/RelayInfoTests.swift index 7dd3f11..f46da79 100644 --- a/Tests/NostrSDKTests/RelayInfoTests.swift +++ b/Tests/NostrSDKTests/RelayInfoTests.swift @@ -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:somebody@nostr.test") XCTAssertEqual(info.supportedNIPs, [1, 2, 4, 9]) @@ -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")