Users class
Users a client wrapper for interacting with the Textile Users API.
This API has the ability to:
Create new identity
Authenticate via identity against ws challenge
Signature:
export declare class Users
Example 1
Initialize Users without identity storage
import { Users } from '@spacehq/users'
const users = new Users({ endpoint: "users.space.storage" });
// create new key pair
const id = users.createIdentity();
// authenticate against ws challenge, obtaining storageAuth
const user = await users.authenticate(id);
Example 2
Initialize Users with BrowserStorage
import { Users, BrowserStorage } from '@spacehq/users'
const storage = new BrowserStorage();
// error is thrown when identity fails to auth
const onErrorCallback = (err, identity) => { ... };
// users are automatically restored from stored identities
const users = await Users.withStorage(storage, { endpoint: "users.space.storage" }, onErrorCallback);
Constructors
Constructor | Modifiers | Description |
---|---|---|
(constructor)(config, storage) | Constructs a new instance of the Users class |
Methods
Method | Modifiers | Description |
---|---|---|
authenticate(identity) | Authenticates the random keypair identity against the hub. Generating an appToken API Session token.If authentication succeeds, a SpaceUser object that can be used with the UserStorage class is returned. | |
backupKeysByPassphrase(uuid, passphrase, backupType, identity) | Backup the existing users identity key information using the passphrase provided.Identity can be gotten from SpaceUser gotten after a successful authentication or recovery. | |
createIdentity() | createIdentity generates a random keypair identity. | |
list() | List all in memory SpaceUser that have been authenticated so far. | |
recoverKeysByPassphrase(uuid, passphrase, backupType) | Recovers users identity key information using the passphrase provided.If successfully recovered, the users information is stored in the IdentityStorage (if provided) when initializing the users class. | |
remove(publicKey) | Removes the users identity from list of authenticated users.It also removes the identity from the IdentityStorage provided. | |
withStorage(storage, config, onError) | static | Creates a users |