UNPKG

textiot

Version:

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

74 lines (73 loc) 2.7 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const api_1 = require("../core/api"); const snapshots_1 = __importDefault(require("./snapshots")); /** * Account is an API module for managing a node account * * @extends API */ class Account extends api_1.API { constructor(opts = api_1.DEFAULT_API_OPTIONS) { super(opts); this.snapshots = new snapshots_1.default(opts); } /** * Retrieve the local node account address * * @returns The current node account's address */ address() { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendGet('account/address'); return response.text(); }); } /** * Retrieve the local node account seed * * @returns The current node account's seed */ seed() { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendGet('account/seed'); return response.text(); }); } /** * Retrieve the local node account's own contact info * * @returns The current node account's contact info */ contact() { return __awaiter(this, void 0, void 0, function* () { const response = yield this.sendGet('account'); return response.json(); }); } /** * Syncs the local node account with all thread snapshots found on the network * * @param apply Whether to apply the discovered thread snapshots as they are found (default false) * @param wait Stops searching after 'wait' seconds have elapsed (max 30 default 2) */ sync(apply, wait) { if (apply) { return this.snapshots.apply(undefined, wait); } return this.snapshots.search(wait); } } exports.default = Account;