Skip to content

Commit

Permalink
Make keychain storage accessible.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Jun 17, 2024
1 parent 7fa2c4f commit 2bd60e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let package = Package(
// ...
.package(
url: "https://github.com/helikon-labs/subvt-data-swift.git",
.upToNextMinor(from: "0.15.0")
.upToNextMinor(from: "0.17.0")
)
],
targets: [
Expand Down
13 changes: 12 additions & 1 deletion Sources/SubVTData/Service/REST/Auth/AuthStorage.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
import KeychainAccess
import secp256k1

Expand All @@ -21,7 +22,7 @@ protocol AuthStorage: AnyObject {
/**
Keychain authentication storage.
*/
class KeychainStorage: AuthStorage {
public class KeychainStorage: AuthStorage {
static let shared: KeychainStorage = KeychainStorage()
var privateKey: PrivateKey
var publicKey: PublicKey
Expand All @@ -46,6 +47,16 @@ class KeychainStorage: AuthStorage {
}
}

public func setPrivateKey(data: Data) {
self.keychain[data: privateKeyKey] = data
self.privateKey = try! PrivateKey(dataRepresentation: data)
self.publicKey = self.privateKey.publicKey
}

public func getPrivateKeyData() -> Data {
return self.privateKey.dataRepresentation
}

func resetUser() {
do {
self.privateKey = try PrivateKey.init()
Expand Down
5 changes: 4 additions & 1 deletion Sources/SubVTData/Util/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ let log = logger()

fileprivate func logger() -> SwiftyBeaver.Type {
let log = SwiftyBeaver.self
log.addDestination(ConsoleDestination())
let console = ConsoleDestination()
if !log.destinations.contains(console) {
log.addDestination(console)
}
return log
}

0 comments on commit 2bd60e4

Please sign in to comment.