-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pluto): pluto will save link secret as a storable key.
BREAKING CHANGE: This makes changes on pluto interface.
- Loading branch information
1 parent
f4a4a80
commit 5d25580
Showing
26 changed files
with
273 additions
and
116 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
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,47 @@ | ||
import AnoncredsSwift | ||
import Domain | ||
import Foundation | ||
|
||
struct LinkSecret: Key { | ||
let keyType = "LinkSecret" | ||
let keySpecifications = [String : String]() | ||
let raw: Data | ||
var size: Int { raw.count } | ||
|
||
let anoncred: AnoncredsSwift.LinkSecret | ||
|
||
init(string: String) throws { | ||
self.anoncred = try AnoncredsSwift.LinkSecret.newFromValue(valueString: string) | ||
guard let strData = string.data(using: .utf8) else { | ||
throw CommonError.invalidCoding(message: "Could not encode LinkSecret in Data") | ||
} | ||
self.raw = strData | ||
} | ||
|
||
init(data: Data) throws { | ||
guard let str = String(data: data, encoding: .utf8) else { | ||
throw CommonError.invalidCoding(message: "Could not encode LinkSecret in String") | ||
} | ||
self.anoncred = try AnoncredsSwift.LinkSecret.newFromValue(valueString: str) | ||
self.raw = data | ||
} | ||
|
||
init() throws { | ||
let anoncred = Prover().createLinkSecret() | ||
self.anoncred = anoncred | ||
guard let strData = try anoncred.getValue().data(using: .utf8) else { | ||
throw CommonError.invalidCoding(message: "Could not encode LinkSecret in Data") | ||
} | ||
self.raw = strData | ||
} | ||
} | ||
|
||
extension LinkSecret: KeychainStorableKey { | ||
var restorationIdentifier: String { "linkSecret+key" } | ||
var storableData: Data { raw } | ||
var index: Int? { nil } | ||
var type: Domain.KeychainStorableKeyProperties.KeyAlgorithm { .rawKey } | ||
var keyClass: Domain.KeychainStorableKeyProperties.KeyType { .privateKey } | ||
var accessiblity: Domain.KeychainStorableKeyProperties.Accessability? { .firstUnlock(deviceOnly: true) } | ||
var synchronizable: Bool { false } | ||
} |
8 changes: 0 additions & 8 deletions
8
AtalaPrismSDK/Apollo/Sources/Operations/CreateLinkSecretOperation.swift
This file was deleted.
Oops, something went wrong.
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
3 changes: 2 additions & 1 deletion
3
AtalaPrismSDK/Pluto/Sources/Domain/Providers/LinkSecretProvider.swift
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,6 +1,7 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol LinkSecretProvider { | ||
func getAll() -> AnyPublisher<[String], Error> | ||
func getAll() -> AnyPublisher<[StorableKey], Error> | ||
} |
3 changes: 2 additions & 1 deletion
3
AtalaPrismSDK/Pluto/Sources/Domain/Stores/LinkSecretStore.swift
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,6 +1,7 @@ | ||
import Combine | ||
import Domain | ||
import Foundation | ||
|
||
protocol LinkSecretStore { | ||
func addLinkSecret(_ linkSecret: String) -> AnyPublisher<Void, Error> | ||
func addLinkSecret(_ linkSecret: StorableKey) -> AnyPublisher<Void, Error> | ||
} |
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
11 changes: 11 additions & 0 deletions
11
AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretProvider.swift
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 Combine | ||
import Foundation | ||
import Domain | ||
|
||
extension CDKeyDAO: LinkSecretProvider { | ||
func getAll() -> AnyPublisher<[StorableKey], Error> { | ||
fetchController(context: readContext) | ||
.tryMap { try $0.map { try $0.parseToStorableKey(keychain: self.keychain) } } | ||
.eraseToAnyPublisher() | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
AtalaPrismSDK/Pluto/Sources/PersistentStorage/DAO/CDKeyDAO+LinkSecretStore.swift
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,73 @@ | ||
import Combine | ||
import CoreData | ||
import Domain | ||
|
||
extension CDKeyDAO: LinkSecretStore { | ||
func addLinkSecret(_ linkSecret: StorableKey) -> AnyPublisher<Void, Error> { | ||
updateOrCreate("linkSecret", context: writeContext) { cdobj, context in | ||
switch linkSecret { | ||
case let keychainKey as KeychainStorableKey: | ||
try storeKeychainKey( | ||
keychainKey: keychainKey, | ||
service: self.keychainService, | ||
account: "linkSecret", | ||
keychain: self.keychain | ||
) | ||
let cdkey = CDKeychainKey(entity: CDKeychainKey.entity(), insertInto: context) | ||
cdkey.parseFromStorableKey( | ||
keychainKey, | ||
identifier: "linkSecret", | ||
service: self.keychainService | ||
) | ||
default: | ||
let cdkey = CDDatabaseKey(entity: CDDatabaseKey.entity(), insertInto: context) | ||
cdkey.parseFromStorableKey( | ||
linkSecret, | ||
identifier: "linkSecret" | ||
) | ||
} | ||
} | ||
.map { _ in } | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
|
||
private func storeKeychainKey( | ||
keychainKey: KeychainStorableKey, | ||
service: String, | ||
account: String, | ||
keychain: KeychainStore | ||
) throws { | ||
try keychain.addKey( | ||
keychainKey, | ||
service: service, | ||
account: account | ||
) | ||
} | ||
|
||
private extension CDDatabaseKey { | ||
func parseFromStorableKey( | ||
_ key: StorableKey, | ||
identifier: String | ||
) { | ||
self.identifier = identifier | ||
self.storableData = key.storableData | ||
self.index = key.index.map { NSNumber(integerLiteral: $0) } | ||
self.restorationIdentifier = key.restorationIdentifier | ||
} | ||
} | ||
|
||
private extension CDKeychainKey { | ||
func parseFromStorableKey( | ||
_ key: KeychainStorableKey, | ||
identifier: String, | ||
service: String | ||
) { | ||
self.identifier = identifier | ||
self.restorationIdentifier = key.restorationIdentifier | ||
self.index = key.index.map { NSNumber(integerLiteral: $0) } | ||
self.type = key.keyClass.rawValue | ||
self.algorithm = key.type.rawValue | ||
self.service = service | ||
} | ||
} |
Oops, something went wrong.