lightwallet¶
Source | Lightwallet |
---|
The lightwallet lib is a wrapper for the original lightwallet.keystore
and bitcore-mnemonic
. It handles logged in users key vaults and encryption.
getKeyStore¶
lightwallet.getKeyStore();
returns CoreBundle.keystore (eth-lightwallet/lib/keystore)
Returns¶
lightwallet.keystore
: keystore library
Example¶
const KeyStore = lightwallet.getKeyStore();
KeyStore.isSeedValid('word1 word2 ... word12');
getMnemonicLib¶
lightwallet.getMnemonicLib();
returns CoreBundle.Mnemonic
Returns¶
bitcore-mnemonic
: the Mnemonic lib
Example¶
const Mnemonic = lightwallet.getMnemonicLib();
var code = new Mnemonic(Mnemonic.Words.SPANISH);
code.toString(); // natal hada sutil año sólido papel jamón combate aula flota ver esfera...
var xpriv = code.toHDPrivateKey();
createVault¶
lightwallet.createVault(mnemonic, password);
Creates a new vault instance to handle lightwallet interactions.
Parameters¶
mnemonic
-string
: mnemonic to create new vault.password
-string
: password to encrypt the vault.
Returns¶
Promise
returns lightwallet.keystore
: vault created using mnemonic, encrypted via password
Example¶
const vault = await lightwallet.createVault(mnemonic, password);
const pwDerivedKey = await lightwallet.keyFromPassword(vault, password);
setVaultActive¶
lightwallet.setVaultActive(vault);
Serializes a specific vault and saves it to the local storage.
Parameters¶
vault
-lightwallet.keystore
: vault to save locally
createVaultAndSetActive¶
lightwallet.createVaultAndSetActive(mnemonic, password);
Create new vault, set it active and set first account id as active one
Parameters¶
mnemonic
-lightwallet.keystore
: mnemonic to create new vault.password
-string
: password to encrypt the vault.
Returns¶
Promise
returns void
: resolved when done
Example¶
await lightwallet.createVaultAndSetActive(mnemonic, password);
const vault = lightwallet.loadVault()
keyFromPassword¶
lightwallet.keyFromPassword(vault, password);
Gets the pwDerivedKey to interact with the vault.
Parameters¶
vault
-object
: The options used for callingpassword
-string
: this can be set if required, defaults to"latest"
Returns¶
Promise
returns Uint8Array
: the pwDerivedKey
Example¶
const vault = await createVault(mnemonic, password);
const pwDerivedKey = await keyFromPassword(vault, password);
getNewVault¶
lightwallet.getNewVault(mnemonic, password);
Creates an new vault and unlocks it
Parameters¶
mnemonic
-lightwallet.keystore
: mnemonic to create new vault.password
-string
: password to encrypt the vault.
Returns¶
Promise
returns lightwallet.keystore
: The new vault.
getAccounts¶
lightwallet.getAccounts(vault, amount);
Get an specific amount of accounts from the vault.
Parameters¶
vault
-lightwallet.keystore
: vault to get accounts fromamount
-number
: number of accounts to return
Returns¶
Array<string>
: The accounts.
getPrivateKey¶
lightwallet.getPrivateKey(vault, accountId);
Gets the private key for an account. Given the derived key, decrypts and returns the private key corresponding to address. This should be done sparingly as the recommended practice is for the keystore to sign transactions using signing.signTx, so there is normally no need to export private keys.
Parameters¶
vault
-object
: vault where the account livesaccountId
-string
: account to get the private key from
Returns¶
string
: accounts private key for submitting transactions, etc.
loadVault¶
lightwallet.loadVault();
Load locked vault from localStorage or unlocked memory vault.
Returns¶
lightwallet.keystore
: deserialized, cached vault
setPasswordFunction¶
lightwallet.setPasswordFunction(arguments);
Sets the password function. The dapp-browser does not includes any library / framework / css that handles a good and nice ui development (e.g. angular, react, bootstrap, …). To handle coporate design and a better DApp development freedom, each DApp must specify its own password dialog. In case of Angular 5 development have a look at the default one, provided by the angular-core: globalPasswordDialog https://github.com/evannetwork/ui-angular-core/blob/4f539a2f5492b137d6be82c133427871073c3929/src/services/evan/bcc.ts#L300
Parameters¶
newPasswordFunction
-Function
: The new password function
getPassword¶
lightwallet.getPassword(accountId);
Shows the global-password modal that should return the users password as a string. Be sure that the “lightwallet.setPasswordFunction” was called before, to setup the password function that should be used.
Parameters¶
accountId
-string
: additional account id to get the password from
Returns¶
Promise
returns string
: password input
loadUnlockedVault¶
lightwallet.loadUnlockedVault();
Return current unlocked vault. Asks for password when vault is locked.
Returns¶
lightwallet.keystore
: unlocked vault
getEncryptionKey¶
lightwallet.getEncryptionKey();
Returns the encryption key for the current password.
Returns¶
Promise
returns string
: encryption key
getEncryptionKeyFromPassword¶
lightwallet.getEncryptionKeyFromPassword(accountId, password);
Hashes a password using sha3.
Parameters¶
accountId
-string
: accountId for that the privateKey should be generatedpassword
-string
: password that should be hashed
Returns¶
string
: resolved when done
Example¶
profile.ipld.keyProvider.setKeysForAccount(
accountId,
lightwallet.getEncryptionKeyFromPassword(accountId, this.password)
);
deleteActiveVault¶
lightwallet.deleteActiveVault();
Remove current active vault from browser.
Example¶
lightwallet.deleteActiveVault();
isValidMnemonic¶
lightwallet.isValidMnemonic(mnemonic);
Returns if an mnemonic is a valid mnemonic. (wrapper for lightwallet.keystore
.isSeedValid)
Parameters¶
mnemonic
-string
: The options used for calling
Returns¶
void
: True if valid mnemonic, False otherwise.