-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from XYOracleNetwork/feature/wallets
Accounts
- Loading branch information
Showing
19 changed files
with
160 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"cSpell.words": ["Alamofire", "keccak", "secp", "unkeyed"] | ||
"cSpell.words": ["Alamofire", "keccak", "Protobuf", "secp", "unkeyed"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Alamofire", | ||
"repositoryURL": "https://github.com/Alamofire/Alamofire.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "e16d3481f5ed35f0472cb93350085853d754913f", | ||
"version": "5.10.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-secp256k1", | ||
"repositoryURL": "https://github.com/21-DOT-DEV/swift-secp256k1", | ||
"state": { | ||
"branch": null, | ||
"revision": "57ce9af6db14e0114af631ace25231a9d0ccccbd", | ||
"version": "0.18.0" | ||
} | ||
"originHash" : "f3249e1a536ee6e8dbb38e511a584a952ad70dd2ca47f9b2313e3410784259cc", | ||
"pins" : [ | ||
{ | ||
"identity" : "alamofire", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/Alamofire/Alamofire.git", | ||
"state" : { | ||
"revision" : "e16d3481f5ed35f0472cb93350085853d754913f", | ||
"version" : "5.10.1" | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
}, | ||
{ | ||
"identity" : "swift-secp256k1", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/21-DOT-DEV/swift-secp256k1", | ||
"state" : { | ||
"revision" : "57ce9af6db14e0114af631ace25231a9d0ccccbd", | ||
"version" : "0.18.0" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 address = XyoAddress(key) | ||
return Account(address: address) | ||
} | ||
|
||
public static func random() -> AccountInstance { | ||
return Account() | ||
} | ||
|
||
init() { | ||
self._account = XyoAddress() | ||
} | ||
|
||
init(address: XyoAddress) { | ||
self._account = address | ||
} | ||
|
||
public var address: Address { | ||
guard let value = self._account.address else { | ||
fatalError("Invalid address") | ||
} | ||
return value as Address | ||
} | ||
|
||
public var addressBytes: Data { | ||
guard let value = self._account.addressBytes else { | ||
fatalError("Invalid addressBytes") | ||
} | ||
return value | ||
} | ||
|
||
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") | ||
} | ||
_previousHash = value | ||
return value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import Foundation | ||
|
||
public protocol AccountInstance { | ||
var address: String? { get } | ||
var addressBytes: Data? { get } | ||
var previousHash: String? { get } | ||
func sign(hash: String) throws -> String? | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Foundation | ||
|
||
public protocol AccountStatic { | ||
// associatedtype T: AccountInstance | ||
// associatedtype C: XyoPayload | ||
|
||
// static func create(options: C?) async throws -> T | ||
static func fromPrivateKey(key: Data?) -> AccountInstance | ||
static func random() -> AccountInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public typealias Address = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public typealias Hash = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
open class AbstractModule: Module { | ||
|
||
private let _account: XyoAddress | ||
private let _account: AccountInstance | ||
|
||
public var account: AccountInstance { | ||
_account | ||
} | ||
|
||
public var address: String? { | ||
_account.addressHex | ||
public var address: Address { | ||
_account.address | ||
} | ||
|
||
public var previousHash: String? { | ||
public var previousHash: Hash? { | ||
_account.previousHash | ||
} | ||
|
||
public init(account: XyoAddress? = nil) { | ||
self._account = account ?? XyoAddress() | ||
public init(account: AccountInstance? = nil) { | ||
self._account = account ?? Account() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
public protocol Module { | ||
var address: String? { get } | ||
var address: Address { get } | ||
var account: AccountInstance { get } | ||
var previousHash: String? { get } | ||
var previousHash: Hash? { get } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
|
||
public class Wallet { | ||
|
||
// public class Wallet: WalletInstance, WalletStatic { | ||
// private let _wallet: HDWallet | ||
|
||
init() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
public protocol WalletInstance: AccountInstance { | ||
var chainCode: String { get } | ||
var depth: Int { get } | ||
var extendedKey: String { get } | ||
var fingerprint: String { get } | ||
var index: Int { get } | ||
var mnemonic: String? { get } | ||
var parentFingerprint: String { get } | ||
var path: String? { get } | ||
var privateKey: String { get } | ||
var publicKey: String { get } | ||
|
||
func derivePath(path: String) throws -> WalletInstance | ||
func neuter() -> WalletInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
public protocol WalletStatic { | ||
|
||
// func create(config: XyoPayload) throws -> WalletInstance | ||
// func fromExtendedKey(key: String) throws -> WalletInstance | ||
// func fromMnemonic(mnemonic: String) throws -> WalletInstance | ||
// func fromPhrase(mnemonic: String, path: String?) throws -> WalletInstance | ||
// func fromSeed(seed: Data) throws -> WalletInstance | ||
func random() -> WalletInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters