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

Formatting & minor updates #35

Merged
merged 10 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cSpell.words": ["Alamofire", "keccak", "secp"]
}
8 changes: 4 additions & 4 deletions Sources/XyoClient/Address/XyoAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ public class XyoAddress {
public var keccakHex: String? {
get {
guard let bytes = keccakBytes else { return nil }
return bytes.toHex(64)
return bytes.toHex(64)
}
}

public var addressBytes: Data? {
get {
guard let keccakBytes = keccakBytes else { return nil }
return keccakBytes.subdata(in: 12..<keccakBytes.count)
return keccakBytes.subdata(in: 12..<keccakBytes.count)
}
}

public var addressHex: String? {
get {
guard let bytes = addressBytes else { return nil }
return bytes.toHex(40)
return bytes.toHex(40)
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ public class XyoAddress {
}

public func generateRandomBytes(_ count: Int = 32) -> Data {

var keyData = Data(count: count)
let result = keyData.withUnsafeMutableBytes {
SecRandomCopyBytes(kSecRandomDefault, 32, $0.baseAddress!)
Expand Down
6 changes: 3 additions & 3 deletions Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Alamofire

public struct XyoApiBoundWitnnessBody: Encodable {
public struct XyoApiBoundWitnessBody: Encodable {
var boundWitnesses: [XyoBoundWitnessJson]
var payloads: [XyoPayload]?
}
Expand Down Expand Up @@ -40,11 +40,11 @@ public class XyoArchivistApiClient {
) throws {
let body = entries
AF.request(
"\(self.config.apiDomain)/archive/\(self.config.archive)/block",
"\(self.config.apiDomain)/\(self.config.apiModule)",
method: .post,
parameters: body,
encoder: JSONParameterEncoder.default
).responseData(queue: XyoArchivistApiClient.queue) { response in
).validate().responseData(queue: XyoArchivistApiClient.queue) { response in
switch response.result {
case .failure( _):
XyoArchivistApiClient.mainQueue.async {
Expand Down
6 changes: 3 additions & 3 deletions Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public class XyoArchivistApiConfig: XyoApiConfig {
var archive: String
public init(_ archive: String, _ apiDomain: String, _ token: String? = nil) {
self.archive = archive
var apiModule: String
public init(_ apiModule: String, _ apiDomain: String, _ token: String? = nil) {
self.apiModule = apiModule
super.init(apiDomain, token)
}
}
2 changes: 1 addition & 1 deletion Sources/XyoClient/Payload/XyoPayloadValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open class XyoPayloadValidator {
closure(errors)
}
}

public func all() -> [String] {
var errors: [String] = []
errors.append(contentsOf: self.schemaValidator.all())
Expand Down
14 changes: 7 additions & 7 deletions Sources/XyoClient/Schema/XyoSchemaValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ open class XyoSchemaValidator {
return self.parts.count
}
}

var isLowercase: Bool {
get {
return self.schema == self.schema.lowercased()
}
}

private func domainLevel(_ level: Int) -> String {
return self.parts[0..<(level + 1)].reversed().joined(separator: ".")

}

var rootDomain: String {
get {
return self.domainLevel(1)
}
}

public func rootDomainExists(_ closure: (_ exists: Bool) -> Void) {
//domainExists(this.rootDomain, closure)
closure(true)
}

public func allDynamic(closure: (_ errors: [String]) -> Void) {
var errors: [String] = []
if (self.schema.isEmpty) {
Expand All @@ -52,7 +52,7 @@ open class XyoSchemaValidator {
}
}
}

public func all() -> [String] {
var errors: [String] = []
if (self.schema.isEmpty) {
Expand Down
20 changes: 9 additions & 11 deletions Sources/XyoClient/XyoPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class XyoPanel {
}

public convenience init(archive: String? = nil, apiDomain: String? = nil, witnesses: [XyoWitness]? = nil, token: String? = nil) {
let apiConfig = XyoArchivistApiConfig(archive ?? XyoPanel.Defaults.apiArchive, apiDomain ?? XyoPanel.Defaults.apiDomain)
let apiConfig = XyoArchivistApiConfig(archive ?? XyoPanel.Defaults.apiModule, apiDomain ?? XyoPanel.Defaults.apiDomain)
let archivist = XyoArchivistApiClient.get(apiConfig)
self.init(archivists: [archivist], witnesses: witnesses ?? [])
}
Expand All @@ -24,7 +24,7 @@ public class XyoPanel {
if let observe = observe {
witnesses.append(XyoEventWitness(observe))
}

self.init(witnesses: witnesses)
} else {
self.init()
Expand All @@ -37,15 +37,15 @@ public class XyoPanel {
private var _witnesses: [XyoWitness]
private var _previous_hash: String?

public func report() throws {
public func report() throws -> [XyoPayload] {
try report(nil)
}

public func event(_ event: String, _ closure: XyoPanelReportCallback?) throws {
public func event(_ event: String, _ closure: XyoPanelReportCallback?) throws -> [XyoPayload] {
try report([XyoEventWitness { previousHash in XyoEventPayload(event, previousHash) }], closure)
}

public func report(_ adhocWitnesses: [XyoWitness], _ closure: XyoPanelReportCallback?) throws {
public func report(_ adhocWitnesses: [XyoWitness], _ closure: XyoPanelReportCallback?) throws -> [XyoPayload] {
var witnesses: [XyoWitness] = []
witnesses.append(contentsOf: adhocWitnesses)
witnesses.append(contentsOf: self._witnesses)
Expand All @@ -70,21 +70,19 @@ public class XyoPanel {
}
}
}
return payloads.compactMap { $0 }
}

public func report(_ closure: XyoPanelReportCallback?) throws {
public func report(_ closure: XyoPanelReportCallback?) throws -> [XyoPayload] {
return try self.report([], closure)
}

struct Defaults {
static let apiArchive = "temp"
static let apiModule = "Archivist"
static let apiDomain = "https://beta.api.archivist.xyo.network"
}

private static var defaultArchivist: XyoArchivistApiClient {
get {
let apiConfig = XyoArchivistApiConfig(self.Defaults.apiArchive, self.Defaults.apiDomain)
return XyoArchivistApiClient.get(apiConfig)
}
XyoArchivistApiClient.get(XyoArchivistApiConfig(self.Defaults.apiModule, self.Defaults.apiDomain))
}
}
12 changes: 6 additions & 6 deletions Sources/XyoClient/XyoWitness/SystemInfo/OsName.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation

func osName() -> String {
#if os(iOS)
#if os(iOS)
return "iOS"
#elseif os(macOS)
#elseif os(macOS)
return "macOS"
#elseif os(watchOS)
#elseif os(watchOS)
return "watchOS"
#elseif os(tvOS)
#elseif os(tvOS)
return "tvOS"
#else
#else
return "unknown"
#endif
#endif
}
26 changes: 13 additions & 13 deletions Sources/XyoClient/XyoWitness/SystemInfo/PathMonitorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ public class PathMonitorManager {
public init(_ start: Bool = true) {
#if os(iOS)
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationWillEnterForeground(notification:)),
name: UIApplication.willEnterForegroundNotification,
object: nil)
self,
selector: #selector(applicationWillEnterForeground(notification:)),
name: UIApplication.willEnterForegroundNotification,
object: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationWillResignActive(notification:)),
name: UIApplication.willResignActiveNotification,
object: nil)
self,
selector: #selector(applicationWillResignActive(notification:)),
name: UIApplication.willResignActiveNotification,
object: nil)
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationWillResignActive(notification:)),
name: UIApplication.willTerminateNotification,
object: nil)
self,
selector: #selector(applicationWillResignActive(notification:)),
name: UIApplication.willTerminateNotification,
object: nil)
#endif
if (start) {
self.start()
Expand Down Expand Up @@ -93,7 +93,7 @@ public class PathMonitorManager {
} else {
self.ip = nil
}

self.group.leave()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ struct XyoSystemInfoCellularProviderPayloadStruct: Encodable {
var mcc: String?
var mnc: String?
init() {
#if os(iOS)
#if os(iOS)
let networkInfo = CTTelephonyNetworkInfo()
let subscriberCellularProvider = networkInfo.serviceSubscriberCellularProviders?.first?.value
name = subscriberCellularProvider?.carrierName
mcc = subscriberCellularProvider?.mobileCountryCode
mnc = subscriberCellularProvider?.mobileNetworkCode
icc = subscriberCellularProvider?.isoCountryCode
allowVoip = subscriberCellularProvider?.allowsVOIP
#endif
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ struct XyoSystemInfoNetworkCellularPayloadStruct: Encodable {
var provider = XyoSystemInfoCellularProviderPayloadStruct()
var radio: String?
init(_ wifiInfo: WifiInformation?) {
#if os(iOS)
#if os(iOS)
let networkInfo = CTTelephonyNetworkInfo()
radio = networkInfo.serviceCurrentRadioAccessTechnology?.first?.value
#endif
#endif
ip = wifiInfo?.pathMonitor?.ip
}
}
32 changes: 16 additions & 16 deletions Sources/XyoClient/XyoWitness/SystemInfo/WifiInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class WifiInformation {
self.pathMonitor = allowPathMonitor ? PathMonitorManager(true) : nil
}

#if os(iOS)
#if os(iOS)
func ssid() -> String? {
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
return nil
Expand All @@ -33,13 +33,13 @@ public class WifiInformation {
}
return ssids.first
}
#elseif os(macOS)
#elseif os(macOS)
func ssid() -> String? {
let client = CWWiFiClient.shared()
let interface = client.interface(withName: nil)
return interface?.ssid()
}
#else
#else
func ssid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
Expand All @@ -52,21 +52,21 @@ public class WifiInformation {
}
return ssid
}
#endif
#endif

#if os(macOS)
#if os(macOS)
func mac() -> String? {
let client = CWWiFiClient.shared()
let interface = client.interface(withName: nil)
return interface?.hardwareAddress()
}
#else
#else
func mac() -> String? {
return nil
}
#endif
#endif

#if os(macOS)
#if os(macOS)
func security() -> String? {
let client = CWWiFiClient.shared()
let interface = client.interface(withName: nil)
Expand Down Expand Up @@ -106,11 +106,11 @@ public class WifiInformation {
return nil
}
}
#else
#else
func security() -> String? {
return nil
}
#endif
#endif

func isWifi() -> Bool {
return pathMonitor?.isWifi ?? false
Expand All @@ -124,27 +124,27 @@ public class WifiInformation {
return pathMonitor?.isCellular ?? false
}

#if os(macOS)
#if os(macOS)
func rssi() -> Int? {
let client = CWWiFiClient.shared()
let interface = client.interface(withName: nil)
return interface?.rssiValue()
}
#else
#else
func rssi() -> Int? {
return nil
}
#endif
#endif

#if os(macOS)
#if os(macOS)
func txPower() -> Int? {
let client = CWWiFiClient.shared()
let interface = client.interface(withName: nil)
return interface?.transmitPower()
}
#else
#else
func txPower() -> Int? {
return nil
}
#endif
#endif
}
2 changes: 1 addition & 1 deletion Sources/XyoClient/extensions/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension Data {
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self)
}
}

mutating func mutablePointer() -> UnsafeMutablePointer<UInt8>! {
return withUnsafeMutableBytes { (bytes: UnsafeMutableRawBufferPointer) -> UnsafeMutablePointer<UInt8>? in
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self)
Expand Down
Loading
Loading