From 2bd60e4f3aad7859a0d0226d007d7ce84b00ff6e Mon Sep 17 00:00:00 2001 From: kukabi Date: Mon, 17 Jun 2024 13:35:30 +0300 Subject: [PATCH] Make keychain storage accessible. --- README.md | 2 +- .../SubVTData/Service/REST/Auth/AuthStorage.swift | 13 ++++++++++++- Sources/SubVTData/Util/Logging.swift | 5 ++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b2f6ca..0e83d34 100644 --- a/README.md +++ b/README.md @@ -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: [ diff --git a/Sources/SubVTData/Service/REST/Auth/AuthStorage.swift b/Sources/SubVTData/Service/REST/Auth/AuthStorage.swift index 765f2c0..40a18cb 100644 --- a/Sources/SubVTData/Service/REST/Auth/AuthStorage.swift +++ b/Sources/SubVTData/Service/REST/Auth/AuthStorage.swift @@ -1,3 +1,4 @@ +import Foundation import KeychainAccess import secp256k1 @@ -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 @@ -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() diff --git a/Sources/SubVTData/Util/Logging.swift b/Sources/SubVTData/Util/Logging.swift index 43dbf13..7796040 100644 --- a/Sources/SubVTData/Util/Logging.swift +++ b/Sources/SubVTData/Util/Logging.swift @@ -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 }