toggleKuwaPasswordVisibility

Toggles the visibility of the kuwa password in the Client

toggleKuwaPasswordVisibility(): void
Returns
void:

paperHeader

This dumb component renders the Kuwa Icon at the top of every page along with its title

paperHeader
Parameters
header (String) title of the page

renderDom

Renders the entire application and passes the store

renderDom

captureVideo

Captures the video in the cordova app using cordova-plugin-media-capture. It first dispatches the CAPTURE_VIDEO_PENDING action to the store while the Client records the Challenge phrase. Once the capture finishes the captureSucess method is called and the CAPTURE_VIDEO_FULFILLED action is dispatched along with the fullpath of the location of the video in the phone. In case the recording fails, the CAPTURE_VIDEO_REJECTED action will be dispatched with the error object as payload

captureVideo(): void
Returns
void:

startScanner

Starts the scanner on the Web client using Instascan package.

startScanner(scanner: Object): void
Parameters
scanner (Object) object created to start the camera on the web client
Returns
void:

Loading

Shows the loading component. Usually rendered when doing GET and POST requests. It is also used when the keypair is being created. More generally it is used when a process is taking place and the user needs to wait for it to complete before he can proceed. This dumb component is rendered within a parent component.

new Loading()

Extends Component

SimpleBottomNavigation

Bottom Navigation appears at the bottom of the page once the video has been uploaded to the Storage Manager. If the registration status is either "New" or "Credentials Provided", the Bottom Navigation will not be rendered. The available links are YourKuwaId, YourStatus, and YourNetwork.

new SimpleBottomNavigation()

Extends React.Component

web3

Create a global variable for the web3 The provider is set using the config value

web3

generalOutcome

generalOutcome is a dumb component where error and success messages can be rendered.

generalOutcome
Parameters
header (String) is the title of the screen
message (String) to show the user for feedback
image (String) url of the image to show to the user for feedback
classes (Object) used to give styling to the component
additionalContent (Component) is a component that can be rendered

togglePasscodeVisibility

Toggles the visibility of the passcode provided by the Sponsor in the Client

togglePasscodeVisibility(): void
Returns
void:

Video

This component controls whether to launch the Android camera or the Webcam depending on what the user is using. In case it is the Web Client, the video.js package is used. In case it is the Cordova application the media capture plugin is used.

new Video()

Extends Component

init

This function is run only in the cordova app. Permissions to access functionalities in an Android device are requested.

init

Shows the navigation bar of The Kuwa Foundation

new Navigation()

Extends React.Component

Error

This component is rendered every time an Exception occurs and is caught. Whenever this component is rendered an error message should be passed to let the user know what went wrong. The help message can be found in the Redux store. The Error component uses the generalOutcome component as a template. Please refer to it for more details.

new Error()

Extends Component

YourStatus

Gets the Registration Status of the Client from his Smart Contract and shows it on the screen along with a short explanation.

new YourStatus()

Extends Component

toggleDropdown

Toggles any dropdown in the navigation bar that has the passed linkName

toggleDropdown(linkName: String): void
Parameters
linkName (String)
Returns
void:

Success

This component is rendered if the user wants to give feedback of success to the user. Whenever this component is rendered a success message is passed. The help message can be found in the Redux store. The Success component uses the generalOutcome component as a template. Please refer to it for more details.

new Success()

Extends Component

ResponsiveDialog

This component appears in two different ways to load the private key of a Wallet: It can be rendered in the Cordova app when the application first loads and detects that there is a Wallet in the filesystem. It can also be rendered if the user manually loads his Wallet in the application from either the Web Client or the Cordova App. In any case, the Client needs to introduce the Kuwa Password to unlock the Wallet and be able to use it.

new ResponsiveDialog()

Extends React.Component

YourNetwork

This component checks the Kuwa Network of the Client in his Smart Contract and renders it in a table.

new YourNetwork()

Extends Component

provideCredentials

Provide Credentials to create a Kuwa ID. The Client is required to provide a password to encrypt his keypair (Kuwa ID and private key) and a passcode provided by the Sponsor. With the provided kuwaPassword a keypair is generated using Keythereum (npm package). First the CREATE_KEYS_PENDING actions is dispatched so that the Loading component is shown on the Client while the keypair is generated. In case the keypair creation fails, the Client will be taken to the Error screen and be asked to try again. Otherwise, the CREATE_KEYS_FULFILLED action will be dispatched and the requestSponsorship function will be called.

provideCredentials(kuwaPassword: string, passcode: string): void
Parameters
kuwaPassword (string) created by the Client
passcode (string) provided (via email) by the Sponsor to the Client
Returns
void:

YourKuwaId

Displays the generated Kuwa ID of the Client and its corresponding QR code. In this component the Client can scan other QR codes that contain Kuwa IDs or can let other users scan his Kuwa ID. In either case, this component controls whether to use the Cordova plugin for QR codes or the Instascan package for the Web Client. Please refer to the online documentation for more details. This component also renders a green box in the cordova application to help the user know where to scan a QR code.

new YourKuwaId()

Extends Component

RecordRegistrationVideo

This component shows the Challenge phrase to be recorded. Depending on the platform that the Client is using (cordova app or web client), different components will be rendered. If it is the cordova app it will use cordova plugins to use the camera of the phone. In the Web client the browser may ask for permission to use the webcam to record a video. As of now the web client recording seems to only work on Chrome. This component uses the Video component to render and record the Video. Please refer to it for more details.

new RecordRegistrationVideo()

Extends Component

Steps

This component simply renders the steps that user will need to follow to obtain a valid Kuwa ID and how to register it.

new Steps()

Extends Component

App

This is where the magic begins. As soon as the application loads, if the Client is using cordova, it will check if it has previously created a Kuwa ID by checking if there are any persisted wallets in his phone. If so, a screen will pop asking the user to input the Kuwa password. Otherwise, the Steps component will be rendered. The entire application uses redux and connected router. Therefore, there is a store that is passed down to the components using the Provider tag. Connected Router is used to make navigation in the app possible (back and forth). Refer to the online documentation of this packages (Redux and Connected Router) to learn more about them. All of the components use the material-ui (https://material-ui.com/getting-started/installation/) for React. Refer to the documenation to understand the rest of the componenets.

new App()

Extends Component

toggleDrawer

When the web client is displayed in a small screen (i.e. mobile phone, not the cordova app) this function shows and hides the navigation bar as a drawer

toggleDrawer()

qrCodeFound

This function is called once a valid QR code containing a Kuwa ID is found and adds the new Kuwa ID to the Kuwa Network. Before adding the QR code, the scanned code is checked to see if it is valid. If it's not valid the action QR_CODE_INVALID is dispatched, otherwise, QR_CODE_FOUND actions id dispatched. After that, it is checked if the scanned Kuwa ID is not already in the Kuwa Network. The scanned Kuwa ID is only added if it is not already in the Kuwa Network. In either case the QR_CODE_UPLOADED action is dispatched. However, in case it is a new Kuwa ID the QR Code Scanned registration status is also updated.

qrCodeFound(scannedKuwaId: String, scanner: Object, contractAddress: String, abi: String, kuwaId: String)
Parameters
scannedKuwaId (String) Scanned Kuwa ID
scanner (Object) object created to start the camera on the web client
contractAddress (String) Address of the Smart Contract
abi (String) of the Smart Contract
kuwaId (String) of the Client Address

webStartVideo

Starts video on the Web Client

webStartVideo(): void
Returns
void:

toggleRestoreState

Toggles the visibility of the screen that serves to restore the state when the user introduces his Kuwa Password when the application first loads and if there is a Custom Wallet in the phone. This action is also dispatched when a Wallet is loaded from the Client.

toggleRestoreState(): void
Returns
void:

ProvideCredentials

The user provides the credentials. The Kuwa Password is created by the user and is used to create his wallet and encrypt it. It's very important for the user NOT to forget this password. The passcode is provided by the Sponsor via email and can be requested by the Client. In the config file, the passcode field can be disabled and the "Test" string will be automatically placed as the default passcode. If so, the Client only needs to provide a Kuwa Password. Also the current component checks that the Kuwa Password and the Passcode fields are not empty. In the future a better check can be implemented and the logic can be moved to the actions folder in order to keep the business logic separate from the View.

new ProvideCredentials()

Extends Component

webFinishedVideo

Dispathces the WEB_CAPTURE_VIDEO_FULFILLED action with the recorded videoBlob as parameter from the Web Client

webFinishedVideo(videoBlob: Blob): void
Parameters
videoBlob (Blob)
Returns
void:

webErrorVideo

In case the video in the web fails, the WEB_CAPTURE_VIDEO_REJECTED action will be dispatched with the video error as payload

webErrorVideo(videoError: Object): void
Parameters
videoError (Object) containing the information of why the video failed
Returns
void:

isValidKuwaId

Check if the scanned QR code is a Kuwa ID. It first checks that it's a string. It has to be 42 characters long including the "0x" at the beginning.

isValidKuwaId(scannedKuwaId: any): boolean
Parameters
scannedKuwaId (any)
Returns
boolean:

requestSponsorship

Request Sponsorship by sending the created keyObject that contains the kuwa ID (Etheruem Address) of the Client and the passcode provided by the Sponsor to the Client. It first dispatches the REQUEST_SPONSORSHIP_PENDING action so that the Loading component appears on the Client's screen. Meanwhile, a POST request is sent to the Sponsor. If an error occurs on the server (i.e. the server is down), the Error is caught and the Client is sent to the Error screen by dispatching REQUEST_SPONSORSHIP_REJECTED. If the passcode is wrong, the Client will be also be sent to the Error screen with a different error message and the sponsorship will also be rejected. In case the passcode is correct the Sponsor will deploy a Smart Contract for the Client. Once the Smart Contract is deployed the REQUEST_SPONSORSHIP_FULFILLED action will be dispatched and the Client will be taken to the RecordRegistrationVideo page. In case the Client is using the Cordova app the state will be automatically persisted as well.

requestSponsorship(keyObject: Object, passcode: String, dispatch: Function): void
Parameters
keyObject (Object) containing the encrypted keypair of the Client
passcode (String) provided (via email) by the Sponsor to the Client
dispatch (Function) function used to dispatch actions to the store
Returns
void:

stopScanner

Stops the web QR scanner and dispatches QR_CODE_STOP_SCAN. This method is called in the callback once a QR code is found.

stopScanner(scanner: Object): void
Parameters
scanner (Object) object created to start the camera on the web client
Returns
void:

stopScan

Stops the scan of the QR scanner on the cordova app and restores the background color. The removeEventListener is supposed to give back the original functionality to back button on the phone, but so far it does not work properly. Once the QR scanner is stopped the action QR_CODE_STOP_SCAN is dispatched.

stopScan(dispatch: Function): Function
Parameters
dispatch (Function) function to dispatch actions to the store
Returns
Function:

mobileStartScanner

Starts the Scanner on the cordova app. It first dispatches the action QR_CODE_SCAN_PENDING after adding the stopScan event listener to the back button of the phone. Therefore, if the Client clicks the back button on the phone the scan is stopped. Once a valid QR code containing a Kuwa ID is found and adds the new Kuwa ID to the Kuwa Network. Before adding the QR code, the scanned code is checked to see if it is valid. If it's not valid the action QR_CODE_INVALID is dispatched, otherwise, QR_CODE_FOUND actions id dispatched. After that, it is checked if the scanned Kuwa ID is not already in the Kuwa Network. The scanned Kuwa ID is only added if it is not already in the Kuwa Network. In either case the QR_CODE_UPLOADED action is dispatched. However, in case it is a new Kuwa ID the QR Code Scanned registration status is also updated.

mobileStartScanner(contractAddress: String, abi: String, kuwaId: String): void
Parameters
contractAddress (String) address of the Smart Contract
abi (String) of the Smart Contract
kuwaId (String) of the Client
Returns
void:

uploadToStorage

Upload to storage the video with the recorded challenge phrase from the cordova app. The function creates a file using the cordova-plugin-file so that it access the filesystem. Then the file is used to create a blob which is apended to the formData object along with the Kuwa ID, the contract abi, and the contract address so that a POST request can be sent to the Storage Manager with this information. Before the blob is created and the information is sent to the Storage Manager, the UPLOAD_TO_STORAGE_PENDING action is dispatched so that the Loading component is shown on the Client. In case the information is not uploaded (i.e. the server is down), the UPLOAD_TO_STORAGE_REJECTED action will be dispatched and the Client will be taken to the Error screen. Otherwise, the Storage Manager will send a response and the UPLOAD_TO_STORAGE_FULFILLED action will be dispatched. This will also persist the state to the mobile filesystem

uploadToStorage(videoFilePath: String, kuwaId: any, abi: any, contractAddress: any): void
Parameters
videoFilePath (String) of the video recorded with the Challenge phrase
kuwaId (any) of the Client
abi (any) of the Contract
contractAddress (any) address of the Contract created by the Sponsor for the Client
Returns
void:

addScannedKuwaId

This method requests the Sponsor to add a scanned Kuwa ID to the Kuwa Network of the Client in the Smart Contract. Since the Sponsor needs to load the contract, the ABI and the Contract Address need to be sent along with the scanned Kuwa ID.

addScannedKuwaId(scannedKuwaId: String, contractAddress: any, abi: any): void
Parameters
scannedKuwaId (String) Scanned Kuwa ID to be added in the Kuwa Network
contractAddress (any) address of the Smart Contract
abi (any) of the Smart Contract
Returns
void:

webUploadToStorage

Upload to storage the video with the recorded challenge phrase from the web client. Using the video.js API a video is recorded on the Client which generates a blob. This blob is apended to the formData object along with the Kuwa ID, the contract abi, and the contract address so that a POST request can be sent to the Storage Manager with this information. Before the blob is created and the information is sent to the Storage Manager, the WEB_UPLOAD_TO_STORAGE_PENDING action is dispatched so that the Loading component is shown on the Client. In case the information is not uploaded (i.e. the server is down), the WEB_UPLOAD_TO_STORAGE_REJECTED action will be dispatched and the Client will be taken to the Error screen. Otherwise, the Storage Manager will send a response and the WEB_UPLOAD_TO_STORAGE_FULFILLED action will be dispatched. This will also persist the state to the mobile filesystem

webUploadToStorage(videoBlob: any, kuwaId: any, abi: any, contractAddress: any): void
Parameters
videoBlob (any) created using video.js on the Client
kuwaId (any) of the Client
abi (any) of the Contract
contractAddress (any) address of the Contract created by the Sponsor for the Client
Returns
void:

generateQrCode

Generate the QR code that contains the Kuwa ID of the client by passing a string that contains the Kuwa ID

generateQrCode(kuwaId: String): Promise
Parameters
kuwaId (String) of the Client
Returns
Promise: that resolves to the url containing the URL of the image with the QR code. This URL can be used as src in an img tag.

setRegistrationStatusTo

Sets the registration status of the Client to whatever is passed in the registrationStatus parameter. Setting the registration status is done by the Sponsor as it requires Ether to update the smart contract. Therefore, the Client sends a request to the Sponsor so that the Sponsor can do it on his behalf. In case the current registration status in the Smart Contract is Valid or Invalid, no request is sent to the Sponsor. Otherwise, the request is sent along with the contract address, its abi, and the Kuwa Id of the Client, so that the Sponsor can load and update the registration status of the smart contract.

setRegistrationStatusTo(registrationStatus: string, contractAddress: string, abi: string, kuwaId: string): void
Parameters
registrationStatus (string) new registration status to be set in the Smart Contract
contractAddress (string) address of the Smart Contract
abi (string) of the Smart Contract
kuwaId (string) Kuwa ID of the Client
Returns
void:

loadState

Loads the state of the application from a jsonFile which is the custom Wallet File.

loadState(jsonFile: File): void
Parameters
jsonFile (File) that contains the Client's wallet information and the Smart Contract information
Returns
void:

restoreState

Restores the state of the application using the wallet file contained in the jsonFile object. The Kuwa Password created by the Client needs to be provided to unlock the wallet, otherwise, the information will not be loaded. Before the information is loaded the RESTORE_STATE_PENDING action is dispatched. Then the information is extracted from the json file and used to load the Client's Smart Contract to get the current registration status.

restoreState(jsonFile: File, kuwaPassword: String, onSuccess: Function): void
Parameters
jsonFile (File) that contains the Client's wallet information and the Smart Contract information
kuwaPassword (String) created by the Client to encrypt the Wallet
onSuccess (Function) is called if the correct password and everything is loaded properly
Returns
void:

getStateFromFile

Converts the jsonFile to json object

getStateFromFile(jsonFile: File): Promise
Parameters
jsonFile (File) that contains the Client's wallet information and the Smart Contract information
Returns
Promise: that resolves to a json object

getPrivateKey

Recovers private key using the Kuwa Password from the Key Object

getPrivateKey(keyObject: Object, kuwaPassword: String): Promise
Parameters
keyObject (Object) json containing the key pair information of the Client
kuwaPassword (String) used by the Client to encrypt his Wallet (key pair)
Returns
Promise: that resolves to the private key of the Client

persistState

Uses the file-saver package to save the custom Wallet in the Web Client to the computers' filesystem. It dispatches the PERSIST_STATE action

persistState(): void
Returns
void:

convertToBase64

Converts any object to base 64. This function is used in the cordova app, so that the Wallet can be sent via email, uploaded to the drive, sent via whatsapp, etc. This is easier than trying to get the file from the phones filesystem and can be easily stored in the store

convertToBase64(dispatch: Function): void
Parameters
dispatch (Function) function to send actions to the Redux store.
Returns
void:

persistStateToMobile

Persist the state of the application to the phone. In this case, the state is the custom Wallet File. The function uses the cordova file plugin to access the filesystem of the phone after a blob is created from the json object. Once the state is persisted the action PERSIST_STATE_TO_MOBILE is dispatched

persistStateToMobile(dispatch: Function): void
Parameters
dispatch (Function) function to dispatch actions to the store
Returns
void:

restoreStateOnMobile

Restore state on mobile is a function that runs when the applications is first loaded to check if a state had been previously persisted in the phone. If no wallet is found the action WALLET_NOT_FOUND is dispatched, otherwise, the action WALLET_FOUND is dispatched and the LOAD_STATE action places the jsonFile in the store so that the state can be restored using the restoreState function

restoreStateOnMobile(onSuccess: Function): void
Parameters
onSuccess (Function) Function called in case the Wallet is found
Returns
void:

getStateToPersist

There is a lot of information in the store, however, only part of it is needed to restore the application where the user last left it off. This function gets all the information that is needed to persist in form of a JSON file. It contains the Custom Wallet

getStateToPersist(): JSON
Returns
JSON: Custom Wallet

exportViaEmail

Sends the wallet via email (or any other service available in the phone to share documents). The function uses the cordova-plugin-email-composer and once the wallet is exported the action MAIL_SENT is dispatched.

exportViaEmail(loadedStateBase64: any): void
Parameters
loadedStateBase64 (any)
Returns
void:

getRegistrationStatus

Gets the registration status from the getRegistrationStatusString function and dispatches the GET_REGISTRATION_STATUS action with the registration status as payload

getRegistrationStatus(abi: String, contractAddress: String, kuwaId: String): void
Parameters
abi (String) of the Smart Contract
contractAddress (String) address of the Smart Contract
kuwaId (String) of the Client
Returns
void:

getKuwaNetwork

Gets the Kuwa Network (the scanned Kuwa IDs of the client) from the getKuwaNetworkList function and dispatches the GET_KUWA_NETWORK action with the Kuwa Network as payload

getKuwaNetwork(abi: String, contractAddress: String, kuwaId: String): void
Parameters
abi (String) of the Smart Contract
contractAddress (String) address of the Smart Contract
kuwaId (String) of the Client
Returns
void:

getKuwaNetworkList

Gets the Kuwa Network List from the Smart Contract. Since this operation does not require ether the values 4300000 and '22000000000' are not used and the Sponsor is not needed.

getKuwaNetworkList(abi: String, contractAddress: String, kuwaId: String): void
Parameters
abi (String) of the Smart Contract
contractAddress (String) address of the Smart Contract
kuwaId (String) of the Client
Returns
void:

getRegistrationStatusString

Gets the Registration Status from the Smart Contract. Since this operation does not require ether the values 4300000 and '22000000000' are not used and the Sponsor is not needed.

getRegistrationStatusString(abi: String, contractAddress: String, kuwaId: String): void
Parameters
abi (String) of the Smart Contract
contractAddress (String) address of the Smart Contract
kuwaId (String) of the Client
Returns
void:

getChallenge

Gets the Challenge from the Smart Contract. Since this operation does not require ether the values 4300000 and '22000000000' are not used and the Sponsor is not needed. Also, in case the Smart Contract Challenge is expired the Client will ask the Sponsor to update the Registration Status

getChallenge(abi: String, contractAddress: String, kuwaId: String): void
Parameters
abi (String) of the Smart Contract
contractAddress (String) address of the Smart Contract
kuwaId (String) of the Client
Returns
void:

loadWallet

Creates a wallet with the provided private key

loadWallet
Parameters
privateKey (string)
Returns
void:

loadContract

Loads a smart contract

loadContract
Parameters
abi (JSON)
contractAddress (string)
gas (number)
gasPrice (string)
from (string)
Returns
void: