Client
public final class Client
Main E3db class to handle data operations.
-
Initializer for the E3db client class.
See also
Client.register(token:clientName:urlSession:apiUrl:completion:)
andClient.register(token:clientName:publicKey:signingKey:urlSession:apiUrl:completion:)
to generate the required Config values.Declaration
Swift
public convenience init(config: Config, urlSession: URLSession = .shared)
Parameters
config
A config object with values that have already been registered with the E3db service.
urlSession
The URLSession to use for the client. Defaults to
URLSession.shared
-
Generate encrypted access key for offline encryption operations.
EAKInfo
objects are safe to store in insecure storage as they are encrypted with the current client’s private key. This method will store the key with E3db for later access.See also
getReaderKey(writerId:userId:type:completion:)
for geting keys from E3db.Declaration
Swift
public func createWriterKey(type: String, completion: @escaping E3dbCompletion<EAKInfo>)
Parameters
type
The kind of data that will be encrypted with this key
completion
A handler to call when this operation completes to provide the EAKInfo result
-
Get the encrypted access key for offline encryption operations. The EAKInfo object must have been created beforehand, and shared with this client.
See also
createWriterKey(type:completion:)
for sending keys to E3db.Declaration
Swift
public func getReaderKey(writerId: UUID, userId: UUID, type: String, completion: @escaping E3dbCompletion<EAKInfo>)
Parameters
writerId
The client ID of the writer of an encrypted document.
userId
The client ID of the user for which an encrypted document was created.
type
The kind of data that will be encrypted with this key
completion
A handler to call when this operation completes to provide the EAKInfo result, or error if not found.
-
A helper function to create a compatible key pair for E3db encryption operations.
Note
This method is not required for library use. A key pair is generated and stored in the
Config
object returned by theClient.register(token:clientName:apiUrl:completion:)
method.See also
Client.register(token:clientName:publicKey:signingKey:urlSession:apiUrl:completion:)
for supplying your own key for registration.Declaration
Swift
public static func generateKeyPair() -> KeyPair?
Return Value
A key pair containing Base64URL encoded Curve25519 public and private keys.
-
A helper function to create a compatible key pair for E3db signature operations.
Note
This method is not required for library use. A key pair is generated and stored in the
Config
object returned by theClient.register(token:clientName:urlSession:apiUrl:completion:)
method.Declaration
Swift
public static func generateSigningKeyPair() -> KeyPair?
Return Value
A key pair containing Base64URL encoded Ed25519 public and private keys.
-
Use the client’s private signing key to create a cryptographic signature over the serialized representation of the given document.
Note
this does not change the document at all (e.g. the values are not encrypted).
Throws
E3dbError.cryptoError
if the operation failedDeclaration
Swift
public func sign<T: Signable>(document: T) throws -> SignedDocument<T>
Parameters
document
A data type that conforms to the
Signable
protocolReturn Value
A wrapper object around a given data type and its cryptographic signature
-
Verify message authenticity. Confirm that the signature for the
SignedDocument
was created by the client identified by the given public key, for the document provided.Throws
E3dbError.cryptoError
if the operation failedDeclaration
Swift
public func verify<T>(signed: SignedDocument<T>, pubSigKey: String) throws -> Bool
Parameters
signed
A wrapper object around a given data type and its cryptographic signature
pubSigKey
The public portion of the key used to create the signature in the
signed
documentReturn Value
Whether the document was signed by the creator of the given public key
-
Create a document to hold data signed for authenticicy and encrypted for confidentiality. The resulting document also holds info related to the author, type of data, and any additional metadata kept in cleartext.
Throws
E3dbError.cryptoError
if the operation failedDeclaration
Swift
public func encrypt(type: String, data: RecordData, eakInfo: EAKInfo, plain: PlainMeta? = nil) throws -> EncryptedDocument
Parameters
type
The kind of data this document represents
data
The cleartext data to be encrypted
eakInfo
The encrypted access key information used for the encryption operation
plain
Additional metadata to be included – remains unencrypted.
Return Value
Data type to hold encrypted data and related info
-
Create a document to hold the original plaintext data from the given encrypted format. The resulting document also holds info related to the author, type of data, and any additional metadata kept in cleartext. The input document is also verified for authenticiy with the given public signing key, and throws an error if verification fails.
Throws
E3dbError.cryptoError
if the decrypt operation fails, or if the document fails verificationDeclaration
Swift
public func decrypt(encryptedDoc: EncryptedDocument, eakInfo: EAKInfo) throws -> DecryptedDocument
Parameters
encryptedDoc
Data type to hold encrypted data and related info
eakInfo
The encrypted access key information used for the decryption operation
Return Value
Data type to hold the unencrypted data and related info
-
Search for records that match a given set of filters.
Note
If the
include_data
flag is not set in the givenQueryParams
, the record results will contain emptyRecordData
values.Declaration
Swift
public func query(params: QueryParams, completion: @escaping E3dbCompletion<QueryResponse>)
Parameters
params
A structure to specify a set of filters for matching records
completion
A handler to call when this operation completes to provide the results of the query
-
Write a record to the E3db service. This will encrypt the
RecordData
fields (leaving the keys as plaintext) then send to E3db for storage. TheRecord
in the response will contain the unencrypted values and additional metadata associated with the record.Declaration
Swift
public func write(type: String, data: RecordData, plain: PlainMeta? = nil, completion: @escaping E3dbCompletion<Record>)
Parameters
type
The kind of data this record represents
data
The unencrypted values for the record
plain
A user-defined, key-value store associated with the record that remains as plaintext
completion
A handler to call when this operation completes to provide the record result
-
Request and decrypt a record from the E3db service.
Declaration
Swift
public func read(recordId: UUID, fields: [String]? = nil, completion: @escaping E3dbCompletion<Record>)
Parameters
recordId
The identifier for the
Record
to readfields
A list of fields to select from the data, instead of the full record data
completion
A handler to call when the operation completes to provide the decrypted record
-
Replace the data and plain metadata for a record identified by its
Meta
. This will overwrite the existing data and metadata values.Declaration
Swift
public func update(meta: Meta, newData: RecordData, plain: PlainMeta?, completion: @escaping E3dbCompletion<Record>)
Parameters
meta
The
Meta
information for the record to updatenewData
The unencrypted values to encrypt and replace for the record
plain
The plaintext key-value store to replace for the record, pass in the existing plain for no changes
completion
A handler to call when the operation completes to provide the updated record
-
Remove the record from the E3db service.
Declaration
Swift
public func delete(recordId: UUID, version: String, completion: @escaping E3dbCompletion<Void>)
-
Provide registration information to the E3db service to create a new client associated with a particular account. The token provided must be generated from Tozny’s Tozny dashboard to register successfully.
Note
This registration variant generates the keypair for the client.
See also
The
register(token:clientName:publicKey:signingKey:urlSession:apiUrl:completion:)
variant of this method allows the caller to provide their own public key.Declaration
Swift
public static func register(token: String, clientName: String, urlSession: URLSession = .shared, apiUrl: String? = nil, completion: @escaping E3dbCompletion<Config>)
Parameters
token
An opaque value associated with an account and generated by the Tozny dashboard
clientName
A name to give this client for registration
urlSession
The URLSession to use for the client. Defaults to
URLSession.shared
apiUrl
The base URL for the E3DB service, uses production API URL if none provided here
completion
A handler to call when this operation completes to provide a complete
Config
-
Provide registration information to the E3db service to create a new client associated with a particular account. The token provided must be generated from Tozny’s Tozny dashboard to register successfully.
Note
This registration variant does not generate the keypair for the client.
See also
The
register(token:clientName:urlSession:apiUrl:completion:)
variant of this method generates the keypair for the caller.Declaration
Swift
public static func register(token: String, clientName: String, publicKey: String, signingKey: String, urlSession: URLSession = .shared, apiUrl: String? = nil, completion: @escaping E3dbCompletion<ClientCredentials>)
Parameters
token
An opaque value associated with an account and generated in the Tozny dashboard
clientName
A name to give this client for registration
publicKey
The public key to register with the E3db service and use for encryption operations
signingKey
The public key to register with the E3db service and use for signing operations
urlSession
The URLSession to use for the client. Defaults to
URLSession.shared
apiUrl
The base URL for the E3DB service, uses production API URL if none provided here
completion
A handler to call when this operation completes to provide
ClientCredentials
used to build aConfig
object for initializing an E3dbClient
-
Write the given file to E3DB. Intended for data from 1MB up to 5GB in size. The contents of the file are encrypted before being uploaded.
Declaration
Swift
public func writeFile(type: String, fileUrl: URL, plain: PlainMeta? = nil, completion: @escaping E3dbCompletion<Meta>)
Parameters
type
The kind of data this record represents
fileUrl
The local URL for the file to upload
plain
A user-defined, key-value store associated with the record that remains as plaintext
completion
A handler to call when this operation completes to provide the file info result
-
Read the file associated with the given record from the server.
Declaration
Swift
public func readFile(recordId: UUID, destination: URL, completion: @escaping E3dbCompletion<Meta>)
-
Allow another user to view and decrypt records of a given type.
Declaration
Swift
public func share(type: String, readerId: UUID, completion: @escaping E3dbCompletion<Void>)
Parameters
type
The kind of records to allow a user to view and decrypt
readerId
The identifier of the user to allow access
completion
A handler to call when this operation completes
-
Share records written by the given writer with the given reader
Declaration
Swift
public func share(onBehalfOf writerId: UUID, type: String, readerId: UUID, completion: @escaping E3dbCompletion<Void>)
Parameters
writerId
The identifier of the client that produced the records
type
The kind of records to allow a user to view and decrypt
readerId
The identifier of the user to allow access
completion
A handler to call when this operation completes
-
Remove a user’s access to view and decrypt records of a given type.
Declaration
Swift
public func revoke(type: String, readerId: UUID, completion: @escaping E3dbCompletion<Void>)
Parameters
type
The kind of records to remove access
readerId
The identifier of the user to remove access
completion
A handler to call when this operation completes
-
Remove permission for the given reader to read records produced by the given writer
Declaration
Swift
public func revoke(onBehalfOf writerId: UUID, type: String, readerId: UUID, completion: @escaping E3dbCompletion<Void>)
Parameters
writerId
The identifier of the client that produced the records
type
The kind of records to remove access
readerId
The identifier of the user to remove access
completion
A handler to call when this operation completes
-
Request the list of policies allowing other users to view and decrypt this client’s records.
Declaration
Swift
public func getOutgoingSharing(completion: @escaping E3dbCompletion<[OutgoingSharingPolicy]>)
Parameters
completion
A handler to call when this operation completes to provide the list of
OutgoingSharingPolicy
objects -
Request the list of policies allowing this client to view and decrypt records written by other users.
Declaration
Swift
public func getIncomingSharing(completion: @escaping E3dbCompletion<[IncomingSharingPolicy]>)
Parameters
completion
A handler to call when this operation completes to provide the list of
IncomingSharingPolicy
objects -
Request the list of policies allowing other clients to perform share and revoke operations on behalf of this client.
Declaration
Swift
public func getAuthorizers(completion: @escaping E3dbCompletion<[AuthorizerPolicy]>)
Parameters
completion
A handler to call when this operation completes to provide the list of
AuthorizerPolicy
objects -
Request the list of policies allowing this client to perform share and revoke operations on behalf of other clients.
Declaration
Swift
public func getAuthorizedBy(completion: @escaping E3dbCompletion<[AuthorizerPolicy]>)
Parameters
completion
A handler to call when this operation completes to provide the list of
AuthorizerPolicy
objects
-
Add an authorizer for records written by this client
Calling this method will grant permission for the
authorizer
client to allow other clients to read records of the given type, written by this client.Declaration
Swift
public func add(authorizerId: UUID, type: String, completion: @escaping E3dbCompletion<Void>)
Parameters
authorizerId
The identifier of the client that can share on the writer’s behalf
type
The kind of records being shared
completion
A handler to call when this operation completes
-
Remove an authorizer for records of a given type written by this client
This method removes the permission granted by
add(authorizerId:type:completion:)
for the provided record type.Declaration
Swift
public func remove(authorizerId: UUID, type: String, completion: @escaping E3dbCompletion<Void>)
Parameters
authorizerId
The identifier of the client that can share on the writer’s behalf
type
The kind of records being shared
completion
A handler to call when this operation completes
-
Remove an authorizer for all records written by this client
This method removes the permission granted by
add(authorizerId:type:completion:)
for all record types.Declaration
Swift
public func remove(authorizerId: UUID, completion: @escaping E3dbCompletion<Void>)
Parameters
authorizerId
The identifier of the client that can share on the writer’s behalf
completion
A handler to call when this operation completes