# Tkey Module Structure

## Doesn't Need any setup
- Storage Layer (User shouldn't even think about it unless they want to use their own)
## Share A
- Service Provider (needs basic setup in constructor)
## Default Modules (Needed for basic operations)
- Share Serialisation Module
- Share Transfer Module
## Share B (Primary Modules)
- Web Storage Module // remove file storage from here
- Chrome Extension Storage Module
- Need a keychain module for mobile // add file storage here
- Secondary modules can be used as primary but not in ideal flows
## Share C (Secondary Modules)
- Security Questions Module
- Seed Phrase Module // not sure how to use it
- Private Key Module // not sure how to use it
## tKey Instantiation Code
```js
export const tKey = new ThresholdKey({
modules: {
webStorage: webStorageModule,
securityQuestions: securityQuestionsModule,
},
customAuthArgs,
});
```
`customAuthArgs` -> Rename to `LoginConfig`
```js
CustomAuthArgs : {
baseUrl: string;
redirectPathName?: string;
redirectToOpener?: boolean;
metadataUrl?: string;
network?: TORUS_NETWORK_TYPE;
networkUrl?: string;
enableLogging?: boolean;
enableOneKey?: boolean;
apiKey?: string;
uxMode?: UX_MODE_TYPE;
locationReplaceOnRedirect?: boolean;
popupFeatures?: string;
storageServerUrl?: string;
}
```
```
LoginConfig : {
redirectUrl: string; // combination of baseUrl & redirectPathName
redirectToNewWindow?: boolean; // rename from redirectToOpener
metadataUrl?: string;
network?: TORUS_NETWORK_TYPE;
networkUrl?: string; // do we need it? Only needed for testnet currently? What will happen in cyan, mainnet & sapphire?
enableLogging?: boolean;
enableOneKey?: boolean;
uxMode?: UX_MODE_TYPE;
popupFeatures?: string;
apiKey?: string; // not sure what this is
locationReplaceOnRedirect?: boolean; // not sure what this is
storageServerUrl?: string; // broadcast-server.tor.us - what's the need for this?
/**
* Any custom state you wish to pass along. This will be returned to you post redirect.
* Use this to store data that you want to be available to the dapp after login.
*/
appState?: string;
}
```
## tKey init
```
tKey.serviceProvider.init(initParams)
```
```
interface InitParams {
/**
* skips the installation / check for service worker
* @defaultValue false
*/
skipSw?: boolean;
/**
* skips the init function
* @defaultValue false
*/
skipInit?: boolean;
/**
* skips the prefetching of redirect url
* @defaultValue false
*
*/
skipPrefetch?: boolean;
}
```
should be changed to something like
- `tkey.init(initParams)`
## Trigger Login
```
tKey.serviceProvider.triggerLogin(SubVerifierDetails)
```
```
interface SubVerifierDetails {
typeOfLogin: LOGIN_TYPE;
verifier: string;
clientId: string;
jwtParams?: Auth0ClientOptions;
hash?: string;
queryParameters?: TorusGenericObject;
customState?: TorusGenericObject;
}
export declare type TorusGenericObject = {
[key: string]: string;
};
```
this should be changed to `tkey.login(LoginParams)`
```
interface LoginParams {
typeOfLogin: LOGIN_TYPE;
verifier: string;
clientId?: string; // this should be optional
// why cannot we pass id token directly here?
jwtParameters?: Auth0ClientOptions;
hash?: string; // what's the use?
queryParameters?: TorusGenericObject; // what's the use?
customState?: TorusGenericObject; // what's the use?
}
export declare type TorusGenericObject = {
[key: string]: string;
};
```
What web3auth currently has
```
declare type LoginConfig = Record<
string,
{
verifier: string;
/**
* The type of login. Refer to enum `LOGIN_TYPE`
*/
typeOfLogin: TypeOfLogin;
/**
* Custom client_id. If not provided, we use the default for openlogin app
*/
clientId?: string;
verifierSubIdentifier?: string;
/**
* Custom jwt parameters to configure the login. Useful for Auth0 configuration
*/
jwtParameters?: JwtParameters;
}
>;
```
this should do `tkey.initialise` internally.
**tKey now in read mode**
## Types
Webstorage module (localstorage + filestorage)
=> Helps tkey store shares on localstorage.
- importShare
- deleteShare
- checkShare => maybe required for UI flows
Chrome extension module
- importShare
- deleteShare
- checkShare
Mobile storage module (Coredata/SQLite/Keychain/icloud on ios)
- importShare
- deleteShare
- checkShare
tkey ??
- no tkey.serviceProvider.init(); tkey.serviceProvider.triggerLogin(); tkey.initialize();
- Change: tkey.init(); tkey.login();
- Change: add init to tkey.triggerLogin(); tkey.initialize();
- Change: add lazy init to contructor + tkey.triggerLogin(); tkey.initialize();
- initialize();
- Login: initialize() should maybe insert webstorage share. This will be possible only in web?
- Shares APIs
- import APIs
- Metadata APIs
It currently contains the following:
```
export interface IModule {
moduleName: string;
setModuleReferences(api: ITKeyApi): void; - usecase?
initialize(): Promise<void>; - usecase?
}
```
---
Why? we have to do currently:
`(tKey.modules.webStorage as any).inputShareFromWebStorage();`
better way to call it:
`tKey.modules.webStorage.import()`