UNPKG

textiot

Version:

A framework for building web and native (IoT) Dapps on the IPFS network

47 lines (46 loc) 1.69 kB
import { API } from '../core/api'; /** * Tokens is an API module for managing Cafe access tokens * * Tokens allow other peers to register with a Cafe peer. Use this API to create, list, validate, * and remove tokens required for access to this Cafe. * * @extends API */ export default class Tokens extends API { /** * Creates an access token * * Generates an access token (44 random bytes) and saves a bcrypt hashed version for future * lookup. The response contains a base58 encoded version of the random bytes token. If the * ‘store’ option is set to false, the token is generated, but not stored in the local Cafe * db. Alternatively, an existing token can be added using by specifying the ‘token’ option. * * @param token Use an existing token, rather than creating a new one * @param store Whether to store the added/generated token to the local db (defaults to true) * @see Cafes#add * @returns New token as string */ add(token?: string, store?: boolean): Promise<string>; /** * Check validity of existing cafe access token * * @param token Access token * @returns Whether token is valid */ validate(token: string): Promise<boolean>; /** * Retrieves information about all stored cafe tokens * * Only really useful for debugging. These are hashed tokens, so are not valid. * @returns Array of bcrypt hashed tokens */ list(): Promise<string[]>; /** * Removes an existing cafe token * * @param token Access token * @returns Whether remove was successful */ remove(token: string): Promise<boolean>; }