set
- set(newIdentity, options)
Sets the identity for the active session (starting one first, if none is active yet). Emits a set event (see Events on the dcp/identity overview page) once the identity is attached.
- Arguments:
newIdentity – Anything accepted as the first argument to the Keystore constructor, a Keystore instance, or a Promise resolving to either.
options (object) – Optional.
options.passphrase (string) – Passphrase to unlock newIdentity with, if it’s already a Keystore.
- Throws:
DCPError with code EHAVEIDENTITY if the session already has an identity – call
logout()first to replace it.- Return type:
Promise<void>
Note
Internally, set() extracts the private key from newIdentity (unlocking it with options.passphrase first, if given) and uses it to construct a brand-new, passphrase-less IdKeystore. The identity you end up with is a copy, not the object you passed in, and it’s unlocked in memory for the lifetime of the session.
Example
const identity = require('dcp/identity');
await identity.set('<api-key>');
const identity = require('dcp/identity');
const wallet = require('dcp/wallet');
const ks = await wallet.load('../path/to/your.keystore');
await identity.set(ks);