diff --git a/Sources/Hedera/Endpoint.swift b/Sources/Hedera/Endpoint.swift index bde4387b..f47422e8 100644 --- a/Sources/Hedera/Endpoint.swift +++ b/Sources/Hedera/Endpoint.swift @@ -72,6 +72,10 @@ extension Endpoint: TryProtobufCodable { port = 50211 } + guard isValidDomainName(proto.domainName) else { + throw HError(kind: .basicParse, description: "Invalid domain name format") + } + self.init(ipAddress: ipAddress, port: port, domainName: proto.domainName) } @@ -83,3 +87,10 @@ extension Endpoint: TryProtobufCodable { } } } + +private func isValidDomainName(_ domainName: String) -> Bool { + let pattern = "^((?!-)[A-Za-z0-9-]{1,63}(?