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

Init

  • Empty

    Declaration

    Swift

    public init()

Storage and Retrieval

  • Securely cache a walelt object, and record a default metadata object

    Declaration

    Swift

    public func cache<T>(wallet: T, childOfIndex: Int?, backedUp: Bool) -> Bool where T : Wallet

    Parameters

    wallet

    An object conforming to Wallet to be stored

    childOfIndex

    An optional Int to denote the index of the HD wallet that this wallet is a child of

    Return 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) -> Bool
  • 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 of

    Return 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
  • Find and return the secure object for a given address

    Declaration

    Swift

    public func fetchWallet(forAddress address: String) -> Wallet?

    Return Value

    Optional object confirming to Wallet protocol

  • 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

Read and Write

Encryption

  • 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 error

    Declaration

    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 error

    Declaration

    Swift

    public func decrypt(_ cipherText: Data) throws -> String

    Parameters

    cipherText

    encrypted cipher text

    Return Value

    cleartext string