CredentialsStore

Given a moduleName and a privateClient, this class provides a getConfig and a setConfig function which you can directly use in your module.  It also deals with optional client-side encryption, and exposes a change event for the config you store in it.  It assumes your module declares a type called ‘config’ using BaseClient.declareType.  Other than that, you will be able to pretty much expose the three methods directly on your module.

Parameters

moduleNameString, the name of the module in which you are using it, but without the “-credentials” suffix.
privClientThe private BaseClient for your module, you get this from the callback call in remoteStorage.defineModule
Summary
CredentialsStoreGiven a moduleName and a privateClient, this class provides a getConfig and a setConfig function which you can directly use in your module.
Functions
setConfigSet the config/credentials
getConfigGet the config/credentials
onRegister an event handler.

Functions

setConfig

CredentialsStore.prototype.setConfig = function(pwd,
config)

Set the config/credentials

Parameters

pwdString value of the password for client-side encryption, or undefined.
configobject, the config/credentials to be saved.

Throws

’config should be an object’ ‘please include sjcl.js (the Stanford JS Crypto Library) in your app’ ‘Schema Not Found’ (if you didn’t call declareType first) ‘Please follow the config schema - (followed by the schema from your declareType)’

getConfig

CredentialsStore.prototype.getConfig = function(pwd)

Get the config/credentials

Parameters

pwdString value of the password for client-side encryption, or undefined.

Throws

’please include sjcl.js (the Stanford JS Crypto Library) in your app’ ‘could not decrypt (moduleName)-config with that password’ ‘could not parse (moduleName)-config as unencrypted JSON’ ‘(moduleName)-config is encrypted, please specify a password for decryption’ ‘(moduleName)-config is not encrypted, or encrypted with a different algorithm’

on

CredentialsStore.prototype.on = function(eventName,
handler)

Register an event handler.  Currently only used for change events.

Parameters

eventNameHas to be the String ‘change’
handlerThe function that should be called when the config changes.  It will be called without any arguments.
CredentialsStore.prototype.setConfig = function(pwd,
config)
Set the config/credentials
CredentialsStore.prototype.getConfig = function(pwd)
Get the config/credentials
CredentialsStore.prototype.on = function(eventName,
handler)
Register an event handler.
Close