WalletCacheService
public class WalletCacheService
A service class used to store and retrieve Wallet
objects such as RegularWallet
, HDWallet
, LedgerWallet
and TorusWallet
from the devices disk.
This class will use the secure enclave (keychain if not available) to generate a key used to encrypt the contents locally, and retrieve.
This class will also store non senstiivve “metadata” about wallets, to allow storage of UI related data users might want to add, without cluttering up the wallet objects themselves
-
Empty
Declaration
Swift
public init()
-
Securely cache a walelt object, and record a default metadata object
Declaration
Swift
public func cache<T>(wallet: T, childOfIndex: Int?, backedUp: Bool) throws where T : Wallet
Parameters
wallet
An object conforming to
Wallet
to be storedchildOfIndex
An optional
Int
to denote the index of the HD wallet that this wallet is a child ofReturn Value
Bool, indicating if the storage was successful or not
-
Cahce a watch wallet metadata obj, only. Metadata cahcing handled via wallet cache method
Declaration
Swift
public func cacheWatchWallet(metadata: WalletMetadata) throws
-
Delete both a secure wallet entry and its related metadata object
Declaration
Swift
public func deleteWallet(withAddress: String, parentIndex: Int?) -> Bool
Parameters
withAddress
The address of the wallet
parentIndex
An optional
Int
to denote the index of the HD wallet that this wallet is a child ofReturn Value
Bool, indicating if the storage was successful or not
-
Clear a watch wallet meatadata obj from the metadata cache only, does not affect actual wallet cache
Declaration
Swift
public func deleteWatchWallet(address: String) -> Bool
-
Migrate a LedgerWallet and its children to a new physical device, denoted by a new UUID
Declaration
Swift
public func migrateLedger(metadata: WalletMetadata, toNewUUID: String) -> Bool
-
Delete the cached files and the assoicate keys used to encrypt it
Declaration
Swift
public func deleteAllCacheAndKeys() -> Bool
Return Value
Bool, indicating if the process was successful or not
-
Write an ordered array of
WalletMetadata
to disk, replacing existing file if existsDeclaration
Swift
public func encryptAndWriteMetadataToDisk(_ metadata: WalletMetadataList) -> Bool
-
Return an ordered array of
WalletMetadata
if present on diskDeclaration
Swift
public func readMetadataFromDiskAndDecrypt() -> WalletMetadataList
-
Load the key references from the secure enclave (or keychain), or create them if non exist
Declaration
Swift
public func loadOrCreateKeys() -> Bool
Return Value
Bool, indicating if operation was successful
-
Clear the key refrences
Declaration
Swift
public func unloadKeys()
-
Delete a key from the secure enclave
Declaration
Swift
public func deleteKey() throws
-
Encrypts string using the Secure Enclave
Throws
CryptoKit errorDeclaration
Swift
public func encrypt(_ string: String) throws -> Data
Parameters
string
clear text to be encrypted
Return Value
cipherText encrypted string
-
Decrypts cipher text using the Secure Enclave
Throws
CryptoKit errorDeclaration
Swift
public func decrypt(_ cipherText: Data) throws -> String
Parameters
cipherText
encrypted cipher text
Return Value
cleartext string