EosioVault

public final class EosioVault

Utility library for managing keys and signing with Apple’s Keychain and Secure Enclave.

  • Notification you can subscribe to notifying of Keychain updates.

    Declaration

    Swift

    public static let updateNotification: Notification.Name
  • The accessGroup allows multiple apps (including extensions) in the same team to share the same Keychain.

    Declaration

    Swift

    public let accessGroup: String
  • Init with accessGroup. The accessGroup allows multiple apps (including extensions) in the same team to share the same Keychain.

    Declaration

    Swift

    public init(accessGroup: String)

    Parameters

    accessGroup

    The access group should be an App Group on the developer account.

  • Get the vaultIdentifierKey (a special Secure Enclave key with tag “VAULT”.) Create if not present.

    Throws

    If a vault key does not exist and cannot be created.

    Declaration

    Swift

    public func vaultIdentifierKey() throws -> Keychain.ECKey

    Return Value

    The vault identifier key, as an ECKey.

  • Get the vaultIdentifierKey public key, as hex.

    Throws

    If a vault key does not exist and cannot be created.

    Declaration

    Swift

    public func vaultIdentifier() throws -> String

    Return Value

    The vaultIdentifierKey public key, as hex.

  • Compute the uncompressed public key for an eosio key

    Throws

    If the uncompressed public key cannot be computed

    Declaration

    Swift

    public func getUncompressedPublicKey(eosioPublicKey: String) throws -> Data

    Parameters

    eosioPublicKey

    The eosio public key

    Return Value

    The uncompressed public key

  • Create a new Secure Enclave key and return the Vault Key.

    Throws

    If a new key cannot be created.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func newSecureEnclaveKey(protection: Keychain.AccessibleProtection = .whenUnlockedThisDeviceOnly,
                                    bioFactor: BioFactor = .none,
                                    metadata: [String: Any]? = nil) throws -> EosioVault.VaultKey

    Parameters

    protection

    Accessibility defaults to whenUnlockedThisDeviceOnly.

    bioFactor

    The BioFactor for this key.

    metadata

    Any metadata to associate with this key.

    Return Value

    The new key as a VaultKey.

  • Create a new elliptic curve key and return as a VaultKey.

    Throws

    If a new key cannot be created.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func newVaultKey(secureEnclave: Bool,
                            protection: Keychain.AccessibleProtection = .whenUnlockedThisDeviceOnly,
                            bioFactor: BioFactor = .none,
                            metadata: [String: Any]? = nil) throws -> EosioVault.VaultKey

    Parameters

    secureEnclave

    Generate this key in Secure Enclave?

    protection

    Accessibility defaults to whenUnlockedThisDeviceOnly.

    bioFactor

    The BioFactor for this key.

    metadata

    Any metadata to associate with this key.

    Return Value

    The new key as a VaultKey.

  • Import an external EOSIO private key into the Keychain. Returns a VaultKey or throws an error.

    Throws

    If the key is not valid or cannot be imported.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func addExternal(eosioPrivateKey: String,
                            protection: Keychain.AccessibleProtection = .whenUnlockedThisDeviceOnly,
                            bioFactor: BioFactor = .none,
                            metadata: [String: Any]? = nil) throws -> EosioVault.VaultKey

    Parameters

    eosioPrivateKey

    An EOSIO private key.

    protection

    Accessibility defaults to .whenUnlockedThisDeviceOnly.

    bioFactor

    The BioFactor for this key.

    metadata

    Any metadata to associate with this key.

    Return Value

    The imported key as a VaultKey.

  • Delete a key given the public key. USE WITH CARE!

    Throws

    If there is an error deleting the key.

    Declaration

    Swift

    public func deleteKey(eosioPublicKey: String) throws

    Parameters

    eosioPublicKey

    The public key for the EOSIO key to delete.

  • Update the label identifying the key.

    Throws

    If the label cannot be updated.

    Declaration

    Swift

    public func update(label: String, publicKey: String) throws

    Parameters

    label

    The new value for the label.

    publicKey

    The public EOSIO key.

  • Update key. (The only items that are updatable are the metadata items.)

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func update(key: EosioVault.VaultKey) -> Bool

    Parameters

    key

    The VaultKey to update.

    Return Value

    True if the key was updated, otherwise false.

  • Get all vault keys and their metadata by combining all Keychain keys (excluding the special VAULT identifier key.)

    Throws

    If there is an error getting the keys.

    Declaration

    Swift

    public func getAllVaultKeys() throws -> [EosioVault.VaultKey]

    Return Value

    An array of VaultKeys.

  • Get the vault key for the eosioPublicKey. IMPORTANT: If the key requires a biometric check for access, the system will prompt the user for FaceID/TouchID

    Throws

    If the key cannot be found.

    Declaration

    Swift

    public func getVaultKey(eosioPublicKey: String) throws -> EosioVault.VaultKey

    Parameters

    eosioPublicKey

    An EOSIO public key.

    Return Value

    A VaultKey.

  • Sign a message with the private key corresponding to the public key if the private key is found in the Keychain. Throws an error if the public key is not valid or the key is not found.

    Declaration

    Swift

    public func sign(message: Data, eosioPublicKey: String, requireBio: Bool, prompt: String = "Sign Transaction", completion: @escaping (String?, EosioError?) -> Void)

    Parameters

    message

    The message to sign.

    eosioPublicKey

    The EOSIO public key corresponding to the key to use for signing.

    requireBio

    Require biometric identification even if the key does not require it.

    completion

    Closure returning an EOSIO signature or an error.

  • Dismiss biometrics dialogue and cancel the sign request.

    Declaration

    Swift

    public func cancelPendingSigningRequest()
  • Save metadata for the eosioPublicKey.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func saveKeyMetadata(eosioPublicKey: String, dictionary: [String : Any]) -> Bool

    Parameters

    eosioPublicKey

    The EOSIO public key.

    dictionary

    A metadata dictionary to save.

    Return Value

    True if the metadata was saved, otherwise false.

  • Delete metadata for the eosioPublicKey.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func deleteKeyMetadata(publicKey: String)

    Parameters

    publicKey

    The public key.

  • Get metadata for the eosioPublicKey.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func getKeyMetadata(eosioPublicKey: String) -> [String : Any]?

    Parameters

    eosioPublicKey

    An EOSIO public key.

    Return Value

    The metadata dictionary for the key, if existing.

  • Get metadata for all keys.

    Important

    Metadata must follow the rules for JSONSerialization.

    Declaration

    Swift

    public func getAllKeysMetadata() -> [String : [String : Any]]?

    Return Value

    Dictionary of metadata dictionaries for all keys.

  • VaultKey collects properties into a single object for an EOSIO elliptic curve key.

    See more

    Declaration

    Swift

    struct VaultKey