api

The main Democracy Web API exported as part of demo-webify webpack'd bundle. Include BrowserFS for backing the file-based Democracy immutable keystore, sending file-based HTTP REST requests, and managing the in-browser wallet.

Call api.init() in your page code when the page has finished loading. Afterwards, you usually want to call the following (in order) api.prepareCachedWallet() to load cached Ethereum address / password in localStorage api.prepareErasePassword() to set up timeout functions to erase the password api.prepareUpdateWhileCached() to set up interval functions while password is still cached.

Source:

Members

(static) utils

Source:

Methods

(static) init(unlockSeconds)

Initialize and populate one-time members of the API

Parameters:
Name Type Description
unlockSeconds Number

default number of seconds to leave wallet unlocked in memory, before the next refresh.

Source:

(static) initFS(listingHTTP)

Initialize the BrowserFS filesystem with the given file listing as an Object of path to null. Each of these paths will be pre-pended with '/api' to match the Democracy REST server.

Example: api.initFS({ 'notes/abc': null })

will map writes of the form fs.writeFileSync('notes/abc') to a POST request to http://{db_host}:{db_port}/api/notes/abc

Parameters:
Name Type Description
listingHTTP Object

paths to map to REST calls.

Source:

(static) prepareCachedWallet(enteredPassword)

Prepare, and if necessary, create and/or load, the Ethereum wallet (address/password) combo for this browser. Call if you need to initially unlock the wallet, or to unlock again after it has been automatically relocked, but you don't need to run api.init(). If the current address and password combo are not valid, create a new one and save into localStorage. Warns user to write down the password.

Parameters:
Name Type Description
enteredPassword String

password to unlock api.thisAddress if desired

Source:

(static) prepareErasePassword(erasePasswordSeconds, erasePasswordCallback)

Prepare timeout function to erase the password for this wallet in the given number of seconds. The erasePasswordTime is cached, but the callback function must be manually registered with this function after every refresh.

Parameters:
Name Type Description
erasePasswordSeconds Number

optional number of seconds to keep password cached, across all page refreshes. if missing, use the previously cached erasePasswordTime

erasePasswordCallback function

Optional, function to call when removing password.

Source:

(static) prepareUpdateWhileCached(updateSeconds, updateCallback)

Prepare interval function to update some status as long as password has not been erased. The updateWhileCachedCallback must be registered after every refresh, it is not cached.

Parameters:
Name Type Description
updateSeconds Number

defaults to 1. Number of seconds to wait between updates.

updateCallback function

Optional, callback function which is given the number of seconds left before password is erased.

Source:

(static) relockErasePassword()

Relock all unlocked accounts in the wallet, clear the saved password and associated timeout/interval IDs and callback functions. Called primarily within api.prepareErasePassword.

Source: