Skip to content

Commit

Permalink
Merge pull request #44 from XYOracleNetwork/feature/naming-standardiz…
Browse files Browse the repository at this point in the history
…ation

Naming Standardization
  • Loading branch information
JoelBCarter authored Nov 14, 2024
2 parents 0566500 + 4774824 commit a4ea0d2
Show file tree
Hide file tree
Showing 61 changed files with 1,636 additions and 1,440 deletions.
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"indentConditionalCompilationBlocks": true,
"indentSwitchCaseLabels": false,
"indentation": {
"spaces": 2
"spaces": 4
},
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
Expand Down
63 changes: 32 additions & 31 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@
import PackageDescription

let package = Package(
name: "XyoClient",
platforms: [
.macOS(.v12),
.iOS(.v13),
.tvOS(.v15),
.watchOS(.v8),
],
products: [
.library(
name: "XyoClient",
targets: ["XyoClient"])
],
dependencies: [
.package(url: "https://github.com/21-DOT-DEV/swift-secp256k1", .upToNextMinor(from: "0.18.0")),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0")),
],
targets: [
.target(name: "keccak"),
.target(
name: "XyoClient",
dependencies: [
.product(name: "secp256k1", package: "swift-secp256k1"),
"Alamofire",
"keccak",
]
),
.testTarget(
name: "XyoClientTests",
dependencies: ["XyoClient"]),
],
swiftLanguageModes: [.v5, .v4_2]
name: "XyoClient",
platforms: [
.macOS(.v12),
.iOS(.v13),
.tvOS(.v15),
.watchOS(.v8),
],
products: [
.library(
name: "XyoClient",
targets: ["XyoClient"])
],
dependencies: [
.package(
url: "https://github.com/21-DOT-DEV/swift-secp256k1", .upToNextMinor(from: "0.18.0")),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.2.0")),
],
targets: [
.target(name: "keccak"),
.target(
name: "XyoClient",
dependencies: [
.product(name: "secp256k1", package: "swift-secp256k1"),
"Alamofire",
"keccak",
]
),
.testTarget(
name: "XyoClientTests",
dependencies: ["XyoClient"]),
],
swiftLanguageModes: [.v5, .v4_2]
)
74 changes: 37 additions & 37 deletions Sources/XyoClient/Address/Account.swift
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
import Foundation

public class Account: AccountInstance, AccountStatic {
let _account: XyoAddress
var _previousHash: String? = nil

public static func fromPrivateKey(key: Data?) -> AccountInstance {
guard let key else {
return Account()
let _account: XyoAddress
var _previousHash: String? = nil

public static func fromPrivateKey(key: Data?) -> AccountInstance {
guard let key else {
return Account()
}
let address = XyoAddress(key)
return Account(address: address)
}
let address = XyoAddress(key)
return Account(address: address)
}

public static func random() -> AccountInstance {
return Account()
}
public static func random() -> AccountInstance {
return Account()
}

init() {
self._account = XyoAddress()
}
init() {
self._account = XyoAddress()
}

init(address: XyoAddress) {
self._account = address
}
init(address: XyoAddress) {
self._account = address
}

public var address: Address {
guard let value = self._account.address else {
fatalError("Invalid address")
public var address: Address {
guard let value = self._account.address else {
fatalError("Invalid address")
}
return value as Address
}
return value as Address
}

public var addressBytes: Data {
guard let value = self._account.addressBytes else {
fatalError("Invalid addressBytes")
public var addressBytes: Data {
guard let value = self._account.addressBytes else {
fatalError("Invalid addressBytes")
}
return value
}
return value
}

public var previousHash: Hash? {
return self._previousHash
}
public var previousHash: Hash? {
return self._previousHash
}

public func sign(hash: Hash) throws -> String {
guard let value = try self._account.sign(hash: hash) else {
fatalError("Error signing hash")
public func sign(hash: Hash) throws -> String {
guard let value = try self._account.sign(hash: hash) else {
fatalError("Error signing hash")
}
_previousHash = value
return value
}
_previousHash = value
return value
}
}
18 changes: 9 additions & 9 deletions Sources/XyoClient/Address/AccountInstance.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation

public protocol AccountInstance {
var address: Address { get }
var addressBytes: Data { get }
var previousHash: Hash? { get }
// var previousHashBytes: Data? { get set }
// var `private`: Data? { get }
// var `public`: Data? { get }
var address: Address { get }
var addressBytes: Data { get }
var previousHash: Hash? { get }
// var previousHashBytes: Data? { get set }
// var `private`: Data? { get }
// var `public`: Data? { get }

func sign(hash: Hash) throws -> String
// func sign(hash: Data, previousHash: Data?) async throws -> Data
// func verify(msg: Data, signature: Data) async throws -> Bool
func sign(hash: Hash) throws -> String
// func sign(hash: Data, previousHash: Data?) async throws -> Data
// func verify(msg: Data, signature: Data) async throws -> Bool
}
10 changes: 5 additions & 5 deletions Sources/XyoClient/Address/AccountStatic.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

public protocol AccountStatic {
// associatedtype T: AccountInstance
// associatedtype C: XyoPayload
// associatedtype T: AccountInstance
// associatedtype C: XyoPayload

// static func create(options: C?) async throws -> T
static func fromPrivateKey(key: Data?) -> AccountInstance
static func random() -> AccountInstance
// static func create(options: C?) async throws -> T
static func fromPrivateKey(key: Data?) -> AccountInstance
static func random() -> AccountInstance
}
8 changes: 4 additions & 4 deletions Sources/XyoClient/Address/Error.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation

enum XyoAddressError: Error {
case invalidPrivateKey
case invalidPrivateKeyLength
case invalidHash
case signingFailed
case invalidPrivateKey
case invalidPrivateKeyLength
case invalidHash
case signingFailed
}
Loading

0 comments on commit a4ea0d2

Please sign in to comment.