This document provides brief descriptions of all public functions, types, and interfaces exposed by the Client API (xxDK). <!-- Each item links to a page with more detail. -->
:::note
If you're new to using the xxDK, you can start with the [Overview](./overview) and [Getting Started](./getting-started) docs.
:::
Note that if you're running the client locally, you can use `go doc` to explore the list of functions and interfaces.
```go
// cd into the `client` directory
godoc-all./api
godoc-all./interfaces
```
## How to Use the API
The API exposes multiple functions, as well as types and their associated method sets. For example, browsing through the API will show you there is a `GetRoundEvents()` callback registration function that lets your client see round events:
`GetRoundEvents()` returns a `RoundEvents` interface. Exploring the broader xxDK for this interface reveals a few functions, such as `AddRoundEvent()` that enable monitoring of a specified event:
```go
typeRoundEventsinterface{
// designates a callback to call on the specified event
// rid is the id of the round the event occurs on
// callback is the callback the event is triggered on
// timeout is the amount of time before an error event is returned
// valid states are the states which the event should trigger on
//Allows the un-registration of a round event before it triggers
Remove(ridid.Round,e*ds.EventCallback)
}
```
Investigating the `callback` parameter of `AddRoundEvent()` yields the following prototype showing that you can receive a full `RoundInfo` object for any round event received by the client on the network:
`DownloadAndVerifySignedNdfWithUrl` retrieves the NDF from a specified URL. The NDF is processed into a protobuf containing a signature which is verified using the cert string passed in. The NDF is returned as marshaled byte data which may be used to start a client.
`NewClient` creates client storage, generates keys, connects, and registers with the network. Note that this does not register a username/identity, but merely creates a new cryptographic identity for adding such information at a later date.
`NewPrecannedClient` creates an insecure user with predetermined keys with nodes. It creates client storage, generates keys, connects, and registers with the network. Note that this does not register a username/identity, but merely creates a new cryptographic identity for adding such information at a later date.
`NewProtoClient_Unsafe` initializes a client object from a JSON containing predefined cryptographic which defines a user. This is designed for some specific deployment procedures and is generally unsafe.
`NewVanityClient` creates a user with a receptionID that starts with the supplied prefix It creates client storage, generates keys, connects, and registers with the network. Note that this does not register a username/identity, but merely creates a new cryptographic identity for adding such information at a later date.
`LoginWithNewBaseNDF_UNSAFE` initializes a client object from existing storage while replacing the base NDF. This is designed for some specific deployment procedures and is generally unsafe.
`LoginWithProtoClient` creates a client object with a protoclient JSON containing the cryptographic primitives. This is designed for some specific deployment procedures and is generally unsafe.
`ConfirmAuthenticatedChannel` creates an authenticated channel out of a valid received request and sends a message to the requestor that the request has been confirmed. It will not run if the network state is not healthy. An error will be returned if a channel already exists, if a request doesn’t exist, or if the passed in contact does not exactly match the received request. Can be retried.
`GetAuthenticatedChannelRequest` returns the contact received in a request if one exists for the given userID. Returns an error if no contact is found.
`GetErrorsChannel` returns a channel which passess errors from the long running threads controlled by `StartNetworkFollower` and `StopNetworkFollower.`
### func (*Client) GetHealth
```go
func(c*Client)GetHealth()interfaces.HealthTracker
```
`GetHealth` returns the health tracker for registration and polling.
`GetNodeRegistrationStatus` gets the current state of node registration in the network. It returns the total number of nodes in the NDF and the number of those which the client is currently registered with. An error is returned if the network is not healthy.
`GetRelationshipFingerprint` returns a unique 15 character fingerprint for an E2E relationship. An error is returned if no relationship with the partner is found.
### func (*Client) GetRng
```go
func(c*Client)GetRng()*fastRNG.StreamGenerator
```
`GetRng` returns the client’s rng (random number generator) object.
`NewCMIXMessage` creates a new cMix message with the right properties for the current cMix network.
### func (*Client) RegisterEventCallback
```go
func(c*Client)RegisterEventCallback(namestring,
myFuncinterfaces.EventCallbackFunction)error
```
`RegisterEventCallback` records the given function to receive `ReportableEvent` objects. It returns the internal index of the callback so that it can be deleted later.
`RegisterForNotifications` allows a client to register for push notifications. Note that clients are not required to register for push notifications especially as these rely on third parties i.e., Firebase, that may represent a security risk to the user.
`RequestAuthenticatedChannel` sends a request to another party to establish an authenticated channel. It will not run if the network state is not healthy. An error will be returned if a channel already exists or if a request was already received. When a confirmation occurs, the channel will be created and the callback will be called. Can be retried.
`SendCMIX` sends a "raw" CMIX message payload to the provided recipient. Note that both `SendE2E` and `SendUnsafe` call `SendCMIX`. Returns the round ID of the round the payload was sent or an error if it fails.
`SendE2E` sends an end-to-end payload to the provided recipient with the provided message type. Returns the list of rounds in which parts of the message were sent or an error if it fails.
`SendManyCMIX` sends many "raw" CMIX message payloads to each of the provided recipients. Used for group chat functionality. Returns the round ID of the round the payload was sent or an error if it fails.
`SendUnsafe` sends an unencrypted payload to the provided recipient with the provided message type. Returns the list of rounds in which parts of the message were sent or an error if it fails. NOTE: Do not use this function unless you know what you are doing.
`StartNetworkFollower` kicks off the tracking of the network. It starts long running network client threads and returns an object for checking state and stopping those threads. Call this when returning from sleep and close when going back to sleep. These threads may become a significant drain on battery when offline; ensure they are stopped if there is no internet access.
**Threads Started:**
1. Network Follower (/network/follow.go) - Tracks the network events and hands them off to workers for handling
2. Historical Round Retrieval (/network/rounds/historical.go) - Retrieves data about rounds which are too old to be stored by the client
3. Message Retrieval Worker Group (/network/rounds/retrieve.go) - Requests all messages in a given round from the gateway of the last node
4. Message Handling Worker Group (/network/message/handle.go) - Decrypts and partitions messages when signals via the Switchboard
5. Health Tracker (/network/health) - Via the network instance tracks the state of the network
6. Garbled Messages (/network/message/garbled.go) - Can be signaled to check all recent messages which could be be decoded
Uses a message store on disk for persistence
7. Critical Messages (/network/message/critical.go) - Ensures all protocol layer mandatory messages are sent
Uses a message store on disk for persistence
8. KeyExchange Trigger (/keyExchange/trigger.go) -Responds to sent rekeys and executes them
9. KeyExchange Confirm (/keyExchange/confirm.go) - Responds to confirmations of successful rekey operations
10. Auth Callback (/auth/callback.go) - Handles both auth confirm and requests
### func (*Client) StopNetworkFollower
```go
func(c*Client)StopNetworkFollower()error
```
`StopNetworkFollower` stops the network follower if it is running. It returns errors if the follower is in the wrong state to stop or if it fails to stop it. If the network follower is running and this fails, the client object will most likely be in an unrecoverable state and need to be trashed.
### func (*Client) UnregisterEventCallback
```go
func(c*Client)UnregisterEventCallback(namestring)
```
`UnregisterEventCallback` deletes the callback identified by the index. It returns an error if it fails.
### func (*Client) UnregisterForNotifications
```go
func(c*Client)UnregisterForNotifications()error
```
`UnregisterForNotifications` turns off notifications for this client.