# Tkey android documentation
# install
### Add Web3Auth to Gradle
In your project-level build.gradle or settings.gradle file, add JitPack repository:
```
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" } // <-- Add this line
}
}
```
Then, in your app-level build.gradle dependencies section, add the following:
```
dependencies {
// ...
// since tkey rust android is not released yet, we should update installation part after package release.
implementation 'package name'
}
```
# initialization
After installation, the next step to use Web3Auth CoreKit SDK is to initialize the SDK. The initialization takes a few steps, including initiating the tKey SDK with the service provider and modules.
## configuration of service provider
Service Provider in tKey is used for generating a Share A, i.e. the private key share managed by a wallet service provider via their authentication flows. This share in our key infrastructure refers to the social login aspect, where we associate a private key share with the user’s social login, enabling the seamless login experience.
In order to configure your service provider, you must use [CustomAuth Android SDK](https://github.com/torusresearch/customauth-android-sdk).
Since CustomAuth Andriod SDK is not automatically installed when you install tkey andriod SDK, let’s start with installation first.
## Usage of CustomAuth Android SDK
You can find more detailed [CustomAuth Android SDK document here](https://github.com/torusresearch/customauth-android-sdk).
1. Install the package
Add the relevant dependency to your project:
```groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'org.torusresearch:customauth-android-sdk:5.0.2'
}
```
2. At verifier's interface (where you obtain client id), please use
`browserRedirectUri` in DirectSdkArgs as the redirect uri. e.g:
browserRedirectUri can be `YOUR_APP_DEEP_LINK` if the OAuth provider supports
it. else, follow the next step If you specify a custom `browserRedirectUri`
or OAuth provider doesn't support deep link url, pls host
[redirect.html](customauth/src/main/java/org/torusresearch/customauth/activity/redirect.html)
at that `browserRedirectUri` after editing `whiteListedURLs` in
[redirect.html](customauth/src/main/java/org/torusresearch/customauth/activity/redirect.html)
with the scheme specified in manifestPlaceHolders and pass in as
`redirectUri`.
3. Register the startup activity in the manifest file using manifest placeholder
in build.gradle file (when a custom scheme is used)
```groovy
android.defaultConfig.manifestPlaceholders = [
'torusRedirectScheme': 'YOUR_APP_SCHEME', // (torusapp)
'torusRedirectHost': 'YOUR_APP_HOST', // (org.torusresearch.customauthandroid)
'torusRedirectPathPrefix': 'YOUR_REDIRECT_PATH' // (/redirect)
]
```
4. Instantiate the package with your own specific client-id and
browserRedirectUri as `YOUR_APP_SCHEME://YOUR_APP_HOST/YOUR_REDIRECT_PATH` (
eg:`torusapp://org.torusresearch.customauthandroid/redirect`)
## After finished configuration of CustomAuth SDK
1. Setup login verifier
Adding LoginVerifier Class is not mandatory, but just
```java
public class LoginVerifier {
private final String name;
private final LoginType typeOfLogin;
private final String clientId;
private final String verifier;
private String domain;
private String verifierIdField;
private boolean isVerfierIdCaseSensitive = true;
public LoginVerifier(String name, LoginType typeOfLogin, String clientId, String verifier) {
this.name = name;
this.typeOfLogin = typeOfLogin;
this.clientId = clientId;
this.verifier = verifier;
}
public LoginVerifier(String name, LoginType typeOfLogin, String clientId, String verifier, String domain) {
this(name, typeOfLogin, clientId, verifier);
this.domain = domain;
}
public LoginVerifier(String name, LoginType typeOfLogin, String clientId, String verifier, String domain, String verifierIdField, boolean isVerfierIdCaseSensitive) {
this(name, typeOfLogin, clientId, verifier, domain);
this.verifierIdField = verifierIdField;
this.isVerfierIdCaseSensitive = isVerfierIdCaseSensitive;
}
public String getDomain() {
return domain;
}
public String getVerifierIdField() {
return verifierIdField;
}
public boolean isVerfierIdCaseSensitive() {
return isVerfierIdCaseSensitive;
}
public String getName() {
return name;
}
public LoginType getTypeOfLogin() {
return typeOfLogin;
}
public String getClientId() {
return clientId;
}
public String getVerifier() {
return verifier;
}
@Override
public String toString() {
return name;
}
}
```
2. setup Login verifier and Auth0ClientOptions
```
selectedLoginVerifier = new LoginVerifier("Google", LoginType.GOOGLE, "your-client-id", "your-verifier");
Auth0ClientOptions.Auth0ClientOptionsBuilder builder = null;
if (this.selectedLoginVerifier.getDomain() != null) {
builder = new Auth0ClientOptions.Auth0ClientOptionsBuilder(this.selectedLoginVerifier.getDomain());
builder.setVerifierIdField(this.selectedLoginVerifier.getVerifierIdField());
builder.setVerifierIdCaseSensitive(this.selectedLoginVerifier.isVerfierIdCaseSensitive());
}
```
3. call triggerLogin()
```
CompletableFuture<TorusLoginResponse> torusLoginResponseCf;
torusLoginResponseCf = this.torusSdk.triggerLogin(new SubVerifierDetails(this.selectedLoginVerifier.getTypeOfLogin(),
this.selectedLoginVerifier.getVerifier(),
this.selectedLoginVerifier.getClientId(), builder.build())
.setPreferCustomTabs(true)
.setAllowedBrowsers(allowedBrowsers));
```
4. handle the result of triggerLogin()
```
torusLoginResponseCf.whenComplete((torusLoginResponse, error) -> {
if (error != null) {
// error handling
} else {
String publicAddress = torusLoginResponse.getPublicAddress();
this.privKey = torusLoginResponse.getPrivateKey();
try {
activity.tkeyProvider = new ServiceProvider(false, this.privKey.toString());
} catch (RuntimeError e) {
throw new RuntimeException(e);
}
}
});
```
* triggerLogin() returns a promise that resolve with a Dictionary that contain at least privateKey and publicAddress field.
5. Initialize the service provider with the privateKey retrived by result of triggerLogin().
```
public ServiceProvider tkeyProvider;
...
activity.tkeyProvider = new ServiceProvider(false, this.privKey.toString(16));
```
# Usage
Once you've installed and successfully instantiated tKey and initialised the service provider in your constructor, you can use it to authenticate your users and generate their tKey shares. Further, you can use a variety of functions exposed by the tKey SDK and its modules to manage different aspects of your users' authentication needs.
We'll be talking in depth about the following operations:
* Logging in the User
* Getting User Information
* Getting tKey Details
* Reconstructing User's Private Key
* Generating a new Share
* Deleting a Share
* Using Modules for Further Operations
* Making Blockchain Calls
## ThresholdKey
Natively, the instance of tKey, (ie. ThresholdKey) returns many functions, however, we have documented a few relevant ones here. You can check the table below for a list of all relevant functions, or the class reference to checkout the full list of functions.
| Function Name | Description | Arguments | Return | Async |
| --- | --- | --- | --- | --- |
| `ThresholdKey` | Constructor for the `ThresholdKey` class. Creates a new threshold key object. | `@Nullable Metadata metadata`, `@Nullable ShareStorePolyIdIndexMap shares`, `StorageLayer storage`, `@Nullable ServiceProvider provider`, `@Nullable LocalMetadataTransitions transitions`, `@Nullable Metadata lastFetchedCloudMetadata`, `boolean enableLogging`, `boolean manualSync` | N/A | No |
| `getMetadata` | Returns the metadata associated with this threshold key. | N/A | `Metadata` | No |
| `initialize` | Initializes the threshold key. | `@Nullable String importShare`, `@Nullable ShareStore input`, `boolean neverInitializedNewKey`, `boolean includeLocalMetadataTransitions`, `ThresholdKeyCallback<KeyDetails> callback` | `Result<KeyDetails>` | Yes |
| `reconstruct` | Reconstructs the threshold key. | `ThresholdKeyCallback<KeyReconstructionDetails> callback` | `Result<KeyReconstructionDetails>` | Yes |
| `generateNewShare` | Generates a new share for the threshold key. | `ThresholdKeyCallback<GenerateShareStoreResult> callback` | `Result<GenerateShareStoreResult>` | Yes |
| `deleteShare` | Deletes a share from the threshold key. | `String shareIndex`, `ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `getKeyDetails` | Returns the key details associated with this threshold key. | N/A | `KeyDetails` | No |
| `outputShare` | Returns a share in string format. | `String shareIndex`, `@Nullable String shareType` | `String` | No |
| `shareToShareStore` | Converts a share in string format to a `ShareStore` object. | `String share` | `ShareStore` | No |
| `inputShare` | Inputs a share with an optional share type | `String share, @Nullable String shareType, ThresholdKeyCallback<Boolean> callback` | `Result<Boolean> ` | Yes |
| `inputShareStore` | Inputs a ShareStore object | `ShareStore store, ThresholdKeyCallback<Boolean> callback` | `Result<Boolean> ` | Yes |
| `outputShareStore` | Retrieves the share store for a given share index and polynomial ID | `String shareIndex, @Nullable String polyId` | `ShareStore` | No |
| `getShareIndexes` | Returns a list of available share indexes | `None` | `ArrayList<String>` | No |
| `getLastFetchedCloudMetadata` | Returns the metadata for the last fetched cloud | `None` | `Metadata` | No |
| `getLocalMetadataTransitions` | Returns the local metadata transitions | `None` | `LocalMetadataTransitions` | No |
| `getTKeyStore` | Returns the TKey store for a given module name | `String moduleName` | `ArrayList<JSONObject> ` | No |
| `getTKeyStoreItem` | Returns a specific TKey store item for a given module name and ID | `String moduleName, String id` | `JSONObject` | No |
| `syncLocalMetadataTransitions` | Synchronizes the local metadata transitions | `ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `getShares` | Returns the share store polynomial ID index map | `None` | `ShareStorePolyIdIndexMap` | No |
| `deleteTKey` | Deletes the TKey | `ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `addShareDescription` | Adds a share description to a key. | `String key, String description, boolean updateMetadata, ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `deleteShareDescription` | Deletes a share description from a key. | `String key, String description, boolean updateMetadata, ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `updateShareDescription` | Updates a share description of a key. | `String key, String oldDescription , String newDescription , boolean updateMetadata , ThresholdKeyCallback<Boolean> callback` | `Result<Boolean>` | Yes |
| `getShareDescriptions` | Gets the share descriptions of all keys. | `None` | `HashMap<String, ArrayList<String>>` | No |
| `finalize` | Frees the native resources. | `None` | `None` | No |
## Login
## Initializing tKey
`public KeyDetails initialize(params)`
Once you have triggered the login process, you're ready to initialize the tKey. This will generate a Threshold Key corresponding to your login provider.
Parameters
`params`
The initialize function accepts the following optional parameters:
| Parameter | Type | Description | Mandatory |
|------------------------------------|----------|-----------------------------------------------|-----------|
| importShare | @Nullable String | Import a share into tkey for initialisation. | No |
| input | @Nullable ShareStore | The input to read from if no share is imported. | No |
| neverInitializedNewKey | boolean | Never initialise using a new key if the shares are already formed | Yes |
| includeLocalMetadataTransitions | boolean | Whether to include local metadata transitions in this setup. | Yes |
## Get User Information
#### `CompletableFuture<TorusLoginResponse> CustomAuth.triggerLogin(SubVerifierDetails var)`
The function `CustomAuth.triggerLogin()` returns a Dictionary which contains the user’s information and details about the login. You can access the information within it to get the user details from the login provider.
### SubVerifierDetails
SubVerifierDetails are the details of each subverifiers to be used.
``` java
public class SubVerifierDetails {
private LoginType typeOfLogin;
private String verifier;
private String clientId;
private Auth0ClientOptions jwtParams;
private Boolean isNewActivity;
private Boolean preferCustomTabs;
private String[] allowedBrowsers;
}
```
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| typeOfLogin | LoginType | Type of your login verifier |
| verifier | String | Verifier Name from Web3Auth Dashboard |
| clientId | String | Client ID from your login service provider |
| jwtParams | Auth0ClientOptions | Additional JWT Params |
| isNewActivity | Boolean | |
| preferCustomTabs | Boolean | |
| allowedBrowsers | String[] | allowed browsers for application ex) "com.android.chrome" |
## Get tKey Details
`thresholdKey.getKeyDetails()`
The function getKeyDetails() returns the details of the keys present generated for the specific user. This includes the public key X & Y of the user, alongside the shares details and the threshold.
### sample keyDetails return
```
[
{
pubKey: {
x: "471dbccd7e55eb2d24..329b8174f2339e516a3d1728d",
y: "3f93da3597ded482fc..b23c5c79011a3deb8ccf8bf50",
},
requiredShares: -9,
threshold: 2,
totalShares: 11,
shareDescriptions: {
"1": [
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671429485524}',
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671429560829}',
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671454332687}',
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671454508464}',
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671454832067}',
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671506806091}',
],
"94da7ea9b8680ea13d..1de31915c54c1cfa055134308969088": [
'{"module":"webStorage","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36","dateAdded":1671424397242}',
],
"9b29f5c69bdcc4c79b..8c573e3001d72dc7a42866e88272866": [
'{"module":"securityQuestions","questions":"whats your password?","dateAdded":1671424430842}',
],
},
},
];
```
From here, you can know whether the user key can be reconstructed or not.
* If the requiredShares is greater than 0, then the key cannot be reconstructed, because this means that the user has not yet generated enough shares to meet the threshold.
* Once the requiredShares is 0 or less than that, then the key can be reconstructed, and the user can use the shares to generate the private key and make further operations on the tKey and manipulate their keys.
class `KeyDetails` includes following functions.
```java
public KeyPoint getPublicKeyPoint()
public int getThreshold()
public int getRequiredShares()
public int getTotalShares()
public String getShareDescriptions()
```
## Reconstruct Private Key
`thresholdKey.reconstructKey()`
The function reconstructKey() reconstructs the private key of the user from the shares generated. This function returns the private key of the user once the threshold has been met.
``` java
# example
KeyReconstructionDetails reconstruct_details = thresholdKey.reconstruct();
String keystr = reconstruct_details.getKey();
```
## Generate a new Share
`thresholdKey.generateNewShare()`
The function generateNewShare() generates a new share on the same threshold set by the user. This function returns the new share generated.
``` java
# example
GenerateShareStoreResult share = thresholdKey.generateNewShare();
```
## Delete a Share
`thresholdKey.deleteShare(shareIndex)`
The function deleteShare() deletes a share from the user's shares. This function returns the updated shareStore after the share has been deleted.
``` java
# example
thresholdKey.deleteShare(share.getIndex());
```
## Using Modules
For making advanced operations on tKey and to manipulate the keys, you can use the modules provided by tKey. As mentioned in the initialisation section, you need to configure the modules beforehand to make it work with tKey. Once that is done, the instance of the respective module is available within your tKey instance and can be used for further operations.
## Making Blockchain Calls
Once you have generated the private key, you can use it to make blockchain calls. The key generated by tKey is of type `secp256k1`, which is compatible with EVM-based blockchains like Ethereum, Polygon, and many others that use the same curve. However, you can also convert this key into other curves and utilize it. For example, we have a dedicated package for converting this module to the `ed25519` curve for usage in Solana and other blockchains that use this curve.
In addition to that, we have dedicated provider packages for EVM and Solana Blockchain libraries. You can check out their respective documentation here:
* Getting a Ethereum Provider from tKey: Ethereum Provider
* Getting a Solana Provider from tKey: Solana Provider
# PrivateKeysModule
The PrivateKeysModule is a utility class that provides methods for setting and retrieving private keys for a Threshold Key instance.
## Public Methods
The following public methods are provided by the PrivateKeysModule class:
### `setPrivateKey(ThresholdKey thresholdKey, @Nullable String key, String format, ThresholdKeyCallback<Boolean> callback)`
Sets the private key for a Threshold Key instance asynchronously.
Parameters:
* thresholdKey: A Threshold Key instance.
* key: The private key value. Can be null if a key needs to be generated.
* format: The format of the private key value.
* callback: A callback that will be called upon completion of the operation.
Returns:
* None
### `getPrivateKeys(ThresholdKey thresholdKey)`
Gets the private keys for a Threshold Key instance synchronously.
Parameters:
* thresholdKey: A Threshold Key instance.
Returns:
A string containing the private keys for the Threshold Key instance.
### `getPrivateKeyAccounts(ThresholdKey thresholdKey)`
Gets the private key accounts for a Threshold Key instance synchronously.
Parameters:
* thresholdKey: A Threshold Key instance.
Returns:
* An ArrayList of strings containing the private key accounts for the Threshold Key instance.
### Native methods
The following methods are native and implemented in C++:
``` java
private static native boolean jniPrivateKeysModuleSetPrivateKey(ThresholdKey thresholdKey, @Nullable String key, String format, String curveN, RuntimeError error);
private static native String jniPrivateKeysModuleGetPrivateKey(ThresholdKey thresholdKey, RuntimeError error);
private static native String jniPrivateKeysModuleGetPrivateKeyAccounts(ThresholdKey thresholdKey, RuntimeError error);
```
# securityquestionModule
The securityquestionModule module provides an interface for setting, getting and managing security question and answer for a ThresholdKey object.
## Public Methods
The following public methods are provided by the securityquestionModule class:
### `generateNewShare(ThresholdKey thresholdKey, String questions, String answer, ThresholdKeyCallback<GenerateShareStoreResult> callback)`
Generates a new share for the security question module with the given security questions and answer for the provided ThresholdKey. The result of the operation will be returned via the callback parameter.
Parameters
* thresholdKey: the ThresholdKey object to use.
* questions: a String containing the security questions.
* answer: a String containing the answer to the security questions.
* callback: a ThresholdKeyCallback object to handle the result of the operation.
### `inputShare(ThresholdKey thresholdKey, String answer, ThresholdKeyCallback<Boolean> callback)`
Inputs a share of the security questions module for the provided ThresholdKey with the given answer. The result of the operation will be returned via the callback parameter.
Parameters
* thresholdKey: the ThresholdKey object to use.
* answer: a String containing the answer to the security questions.
* callback: a ThresholdKeyCallback object to handle the result of the operation.
### `changeSecurityQuestionAndAnswer(ThresholdKey thresholdKey, String questions, String answer, ThresholdKeyCallback<Boolean> callback)`
Changes the security questions and answer for the provided ThresholdKey with the given questions and answer. The result of the operation will be returned via the callback parameter.
Parameters
* thresholdKey: the ThresholdKey object to use.
* questions: a String containing the new security questions.
* answer: a String containing the new answer to the security questions.
* callback: a ThresholdKeyCallback object to handle the result of the operation.
### `storeAnswer(ThresholdKey thresholdKey, String answer, ThresholdKeyCallback<Boolean> callback)`
Stores the answer to the security questions for the provided ThresholdKey. The result of the operation will be returned via the callback parameter.
Parameters
* thresholdKey: the ThresholdKey object to use.
* answer: a String containing the answer to the security questions.
* callback: a ThresholdKeyCallback object to handle the result of the operation.
### `getAnswer(ThresholdKey thresholdKey) throws RuntimeError`
Gets the answer to the security questions for the provided ThresholdKey.
Parameters
* thresholdKey: the ThresholdKey object to use.
Returns
* a String containing the answer to the security questions.
### `getQuestions(ThresholdKey thresholdKey) throws RuntimeError`
Gets the security questions for the provided ThresholdKey.
Parameters
* thresholdKey: the ThresholdKey object to use.
Returns
* a String containing the security questions.
### Native methods
The following methods are native and implemented in C++:
``` java
private static native long jniSecurityQuestionModuleGenerateShareStoreResult(ThresholdKey thresholdKey, String questions, String answer, String curveN, RuntimeError error);
private static native boolean jniSecurityQuestionModuleInputShare(ThresholdKey thresholdKey, String answer, String curveN, RuntimeError error);
private static native boolean jniSecurityQuestionModuleChangeQuestionAndAnswer(ThresholdKey thresholdKey, String questions, String answer, String curveN, RuntimeError error);
private static native boolean jniSecurityQuestionModuleStoreAnswer(ThresholdKey thresholdKey, String answer, String curveN, RuntimeError error);
private static native String jniSecurityQuestionModuleGetAnswer(ThresholdKey thresholdKey, RuntimeError error);
private static native String jniSecurityQuestionModuleGetQuestions(ThresholdKey thresholdKey, RuntimeError error);
```
# SeedPhraseModule
This module provides functionality for setting, changing, retrieving, and deleting seed phrases in a ThresholdKey object.
## Public Methods
The following public methods are provided by the SeedPhraseModule class:
### `public static void setSeedPhrase(ThresholdKey thresholdKey, String format, @Nullable String phrase, int wallets, ThresholdKeyCallback<Boolean> callback)`
Sets a seed phrase for a ThresholdKey object.
Parameters:
* thresholdKey - the ThresholdKey object to set the seed phrase for.
* format - the format of the seed phrase. Currently supported formats are "mnemonic" and "hex".
* phrase - the seed phrase to set. Can be null, in which case a new seed phrase will be generated.
* wallets - the number of wallets to derive from the seed phrase.
* callback - a callback that will be called when the operation completes.
### `public static void changePhrase(ThresholdKey thresholdKey, String oldPhrase, String newPhrase, ThresholdKeyCallback<Boolean> callback)`
Changes the seed phrase for a ThresholdKey object.
Parameters:
* thresholdKey - the ThresholdKey object to change the seed phrase for.
* oldPhrase - the current seed phrase.
* newPhrase - the new seed phrase.
* callback - a callback that will be called when the operation completes.
### `public static String getPhrases(ThresholdKey thresholdKey) throws RuntimeError`
Retrieves all seed phrases associated with a ThresholdKey object.
Parameters:
* thresholdKey - the ThresholdKey object to retrieve seed phrases for.
Returns:
* a string containing all seed phrases associated with the ThresholdKey object.
Throws:
* RuntimeError - if an error occurs during the operation.
### `public static void deletePhrase(ThresholdKey thresholdKey, String phrase, ThresholdKeyCallback<Boolean> callback)`
Deletes a seed phrase associated with a ThresholdKey object.
Parameters:
* thresholdKey - the ThresholdKey object to delete the seed phrase from.
* phrase - the seed phrase to delete. If null, all seed phrases will be deleted.
* callback - a callback that will be called when the operation completes.
### Native methods
The following methods are native and implemented in C++:
``` java
private static native void jniSeedPhraseModuleSetSeedPhrase(ThresholdKey thresholdKey, String format, String phrase, int wallets, String curveN, RuntimeError error);
private static native void jniSeedPhraseModuleChangePhrase(ThresholdKey thresholdKey, String oldPhrase, String newPhrase, String curveN, RuntimeError error);
private static native String jniSeedPhraseModuleGetSeedPhrases(ThresholdKey thresholdKey, RuntimeError error);
private static native void jniSeedPhraseModuleDeletePhrase(ThresholdKey thresholdKey, @Nullable String phrase, RuntimeError error);
```
# ShareSerializationModule
The ShareSerializationModule is a utility class that provides methods to serialize and deserialize threshold key shares.
## Public Methods
The following public methods are provided by the ShareSerializationModule class:
Methods
### `public static String serializeShare(ThresholdKey thresholdKey, String share, @Nullable String format) throws RuntimeError`
This method serializes a threshold key share.
Parameters
* thresholdKey - The threshold key object associated with the share.
* share - The share to serialize.
* format - The format to use for serialization. This is an optional parameter that defaults to "json" if not specified.
Returns
* A string representing the serialized share.
Throws
* RuntimeError - If an error occurs during serialization.
### `public static String deserializeShare(ThresholdKey thresholdKey, String share, @Nullable String format) throws RuntimeError`
This method deserializes a threshold key share.
Parameters
* thresholdKey - The threshold key object associated with the share.
* share - The serialized share to deserialize.
* format - The format to use for deserialization. This is an optional parameter that defaults to "json" if not specified.
Returns
* A string representing the deserialized share.
Throws
* RuntimeError - If an error occurs during deserialization.
### Native methods
The following methods are native and implemented in C++:
``` java
private static native String jniShareSerializationModuleSerializeShare(ThresholdKey thresholdKey, String share, @Nullable String format, RuntimeError error);
private static native String jniShareSerializationModuleDeserializeShare(ThresholdKey thresholdKey, String share, @Nullable String format, RuntimeError error);
```
# ShareTransferModule
The ShareTransferModule is a Swift module that provides functions for requesting, approving and transfering a share to another device/ storage.
## Public Methods
The following public methods are provided by the ShareTransferModule class:
### `public static void requestNewShare(ThresholdKey thresholdKey, String userAgent, String availableShareIndexes, ThresholdKeyCallback<String> callback)`
This function sends a request to obtain a new share for the given thresholdKey. The userAgent and availableShareIndexes parameters are included in the request. The callback parameter is called when the operation is complete.
Parameters
* thresholdKey : A ThresholdKey object representing the threshold key for which to request a new share.
* userAgent : A String representing the user agent to include in the request.
* availableShareIndexes : A String representing the available share indexes to include in the request.
* callback : A `ThresholdKeyCallback<String>` object representing the callback function to call when the operation is complete.
Return
* This function does not return a value directly. The result of the operation is passed to the callback function as a `Result<String>` object.
### `public static void addCustomInfoToRequest(ThresholdKey thresholdKey, String encPubKeyX, String customInfo, ThresholdKeyCallback<Boolean> callback)`
This function adds custom information to a share request for the given thresholdKey. The encPubKeyX and customInfo parameters are included in the request. The callback parameter is called when the operation is complete.
Parameters
* thresholdKey : A ThresholdKey object representing the threshold key to which to add custom information.
* encPubKeyX : A String representing the encrypted public key to include in the request.
* customInfo : A String representing the custom information to include in the request.
* callback : A `ThresholdKeyCallback<Boolean>` object representing the callback function to call when the operation is complete.
Return
* This function does not return a value directly. The result of the operation is passed to the callback function as a `Result<Boolean>` object.
### `public static void lookForRequest(ThresholdKey thresholdKey, ThresholdKeyCallback<ArrayList<String>> callback)`
This function looks for share requests for the given thresholdKey. The callback parameter is called when the operation is complete.
Parameters
* thresholdKey : A ThresholdKey object representing the threshold key for which to look for share requests.
* callback : A `ThresholdKeyCallback<ArrayList<String>>` object representing the callback function to call when the operation is complete.
Return
* This function does not return a value directly. The result of the operation is passed to the callback function as a `Result<ArrayList<String>>` object. The result contains an ArrayList of String objects, each representing a share request.
### `public static void approveRequest(ThresholdKey thresholdKey, String encPubKeyX, @Nullable ShareStore store, ThresholdKeyCallback<Boolean> callback)`
This function is used to approve a threshold key request. It is an asynchronous function, which means that it is executed in a separate thread, and the result is returned via a callback function.
Parameters
* thresholdKey: The threshold key object.
* encPubKeyX: The encrypted public key.
* store: A share store object (can be null).
* callback: The callback function to be executed when the function completes.
Return
* The function returns a boolean value via the callback function to indicate if the request was approved successfully.
### `public static void approveRequestWithShareIndex(ThresholdKey thresholdKey, String encPubKeyX, String shareIndex, ThresholdKeyCallback<Boolean> callback)`
This function is used to approve a threshold key request using a specific share index. It is an asynchronous function, which means that it is executed in a separate thread, and the result is returned via a callback function.
Parameters
* thresholdKey: The threshold key object.
* encPubKeyX: The encrypted public key.
* shareIndex: The index of the share to use for approval.
* callback: The callback function to be executed when the function completes.
Return
* The function returns a boolean value via the callback function to indicate if the request was approved successfully.
### `public static void getStore(ThresholdKey thresholdKey, ThresholdKeyCallback<ShareTransferStore> callback)`
This function is used to get the share transfer store associated with a threshold key. It is an asynchronous function, which means that it is executed in a separate thread, and the result is returned via a callback function.
Parameters
* thresholdKey: The threshold key object.
* callback: The callback function to be executed when the function completes.
Return
* The function returns a ShareTransferStore object via the callback function, which represents the share transfer store associated with the threshold key.
### `public static void setStore(ThresholdKey thresholdKey, ShareTransferStore store, ThresholdKeyCallback<Boolean> callback)`
This function is used to set the share transfer store associated with a threshold key. It is an asynchronous function, which means that it is executed in a separate thread, and the result is returned via a callback function.
Parameters
* thresholdKey: The threshold key object.
* store: A share transfer store object.
* callback: The callback function to be executed when the function completes.
Return
* The function returns a boolean value via the callback function to indicate if the operation was successful.
### `public static void deleteStore(ThresholdKey thresholdKey, String encPubKeyX, ThresholdKeyCallback<Boolean> callback)`
This function deletes the share store associated with a given threshold key and encrypted public key.
Parameters
* thresholdKey - The threshold key associated with the share store to be deleted.
* encPubKeyX - The encrypted public key associated with the share store to be deleted.
* callback - A callback function that is called once the operation is complete. The callback function takes a Result<Boolean> object as its parameter.
Return
* The function returns a boolean value via the callback function to indicate if the operation was successful.
### `public static String getCurrentEncryptionKey(ThresholdKey thresholdKey) throws RuntimeError`
This function returns the current encryption key associated with a given threshold key.
Parameter
* thresholdKey - The threshold key whose encryption key is to be retrieved.
Return
* A String representing the current encryption key.
Throws
* RuntimeError - if an error occurs during the operation.
### `public static void requestStatusCheck(ThresholdKey thresholdKey, String encPubKeyX, Boolean deleteRequestOnCompletion, ThresholdKeyCallback<ShareStore> callback)`
This function requests the status of a share store associated with a given threshold key and encrypted public key.
Parameter
* thresholdKey - The threshold key associated with the share store whose status is being requested.
* encPubKeyX - The encrypted public key associated with the share store whose status is being requested.
* deleteRequestOnCompletion - A Boolean value indicating whether the request should be deleted upon completion.
* callback - A callback function that is called once the operation is complete. The callback function takes a Result<ShareStore> object as its parameter.
Return
* The function returns a Result<ShareStore> object value via the callback function to indicate if the operation was successful.
### `public static void cleanupRequest(ThresholdKey thresholdKey) throws RuntimeError`
This function cleans up a request associated with a given threshold key.
Parameter
* thresholdKey - The threshold key associated with the request to be cleaned up.
Return
* None
Throws
* RuntimeError - if an error occurs during the operation.
### Native methods
The following methods are native and implemented in C++:
``` java
private static native String jniSharetransferModuleRequestNewShare(ThresholdKey thresholdKey, String agent, String indexes, String curveN, RuntimeError error);
private static native void jniSharetransferModuleAddCustomInfoToRequest(ThresholdKey thresholdKey, String encPubKeyX, String customInfo, String curveN, RuntimeError error);
private static native String jniSharetransferModuleLookForRequest(ThresholdKey thresholdKey, RuntimeError error);
private static native void jniSharetransferModuleApproveRequest(ThresholdKey thresholdKey, String encPubKeyX, @Nullable ShareStore shareStore, String curveN, RuntimeError error);
private static native void jniSharetransferModuleApproveRequestWithShareIndex(ThresholdKey thresholdKey, String encPubKeyX, String indexes, String curveN, RuntimeError error);
private static native long jniSharetransferModuleGetStore(ThresholdKey thresholdKey, RuntimeError error);
private static native boolean jniSharetransferModuleSetStore(ThresholdKey thresholdKey, ShareTransferStore shareStore, String curveN, RuntimeError error);
private static native boolean jniSharetransferModuleDeleteStore(ThresholdKey thresholdKey, String encPubKeyX, String curveN, RuntimeError error);
private static native String jniSharetransferModuleGetCurrentEncryptionKey(ThresholdKey thresholdKey, RuntimeError error);
private static native long jniSharetransferModuleRequestStatusCheck(ThresholdKey thresholdKey, String encPubKeyX, boolean deleteOnCompletion, String curveN, RuntimeError error);
private static native void jniSharetransferModuleCleanupRequest(ThresholdKey thresholdKey, RuntimeError error);
```