Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

did:dht resolution #15

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let package = Package(
.package(url: "https://github.com/WeTransfer/Mocker.git", .upToNextMajor(from: "3.0.1")),
.package(url: "https://github.com/allegro/swift-junit.git", from: "2.1.0"),
.package(url: "https://github.com/flight-school/anycodable.git", from: "0.6.7"),
.package(url: "https://github.com/Bouke/DNS.git", from: "1.2.0"),
],
targets: [
.target(
Expand All @@ -28,13 +29,15 @@ let package = Package(
.product(name: "secp256k1", package: "secp256k1.swift"),
.product(name: "ExtrasBase64", package: "swift-extras-base64"),
.product(name: "AnyCodable", package: "anycodable"),
.product(name: "DNS", package: "DNS"),
]
),
.testTarget(
name: "Web5Tests",
dependencies: [
"Web5",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "Mocker", package: "Mocker"),
]
),
.testTarget(
Expand Down
24 changes: 24 additions & 0 deletions Sources/Web5/Common/DNS+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import DNS
import Foundation

extension DNS.TextRecord {

/// Create a new text record, with values instead of attributes
init(
name: String,
ttl: UInt32,
values: [String]
) {
var record = TextRecord(
name: name,
unique: false,
internetClass: .internet,
ttl: ttl,
attributes: [:]
)
record.values = values
self = record
}


}
30 changes: 30 additions & 0 deletions Sources/Web5/Common/OneOrMany.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ public enum OneOrMany<T: Codable & Equatable>: Codable, Equatable {
case one(T)
case many([T])

public init(_ value: T) {
self = .one(value)
}

public init?(_ value: T?) {
if let value {
self.init(value)
} else {
return nil
}
}

public init?(_ values: [T]) {
if values.count >= 2 {
self = .many(values)
} else if values.count == 1 {
self = .one(values.first!)
} else {
return nil
}
}

public init?(_ values: [T]?) {
if let values {
self.init(values)
} else {
return nil
}
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let singleValue = try? container.decode(T.self) {
Expand Down
Loading
Loading