UNPKG

textiot

Version:

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

111 lines (110 loc) 3.49 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cancelSync = exports.sync = exports.contact = exports.decrypt = exports.encrypt = exports.seed = exports.address = void 0; const react_native_1 = require("react-native"); const buffer_1 = require("buffer"); const model_1 = require("./model"); const { AccountBridge } = react_native_1.NativeModules; /** * Get the account address. * * ```typescript * const address = Textile.account.address(); * ``` */ function address() { return __awaiter(this, void 0, void 0, function* () { const result = yield AccountBridge.address(); return result; }); } exports.address = address; /** * Get the account seed phrase to display to user. * * ```typescript * const seed = Textile.account.seed(); * ``` */ function seed() { return __awaiter(this, void 0, void 0, function* () { const result = yield AccountBridge.seed(); return result; }); } exports.seed = seed; /** * Encrypt data with the account address. * * ```typescript * const encrypted = Textile.account.encrypt(Buffer.from(JSON.stringify({foo:"bar"}))); * ``` */ function encrypt(input) { return __awaiter(this, void 0, void 0, function* () { const result = yield AccountBridge.encrypt(input.toString('base64')); return buffer_1.Buffer.from(result, 'base64'); }); } exports.encrypt = encrypt; /** * Decrypt data previously encrypted with the account address. * * ```typescript * const decrypted = Textile.account.decrypt(encrypted); * ``` */ function decrypt(input) { return __awaiter(this, void 0, void 0, function* () { const result = yield AccountBridge.decrypt(input.toString('base64')); return buffer_1.Buffer.from(result, 'base64'); }); } exports.decrypt = decrypt; /** * List all own contact. * * ```typescript * const contact: IContact = Textile.account.contact(); * ``` */ function contact() { return __awaiter(this, void 0, void 0, function* () { const result = yield AccountBridge.contact(); return model_1.Contact.decode(buffer_1.Buffer.from(result, 'base64')); }); } exports.contact = contact; /** * Search and apply account thread snapshots. * ```typescript * Textile.account.sync(options); * ``` */ function sync(options) { return __awaiter(this, void 0, void 0, function* () { return AccountBridge.sync(buffer_1.Buffer.from(model_1.QueryOptions.encode(options).finish()).toString('base64')); }); } exports.sync = sync; /** * Cancel an ongoing Thread backup search. * ```typescript * Textile.account.cancelSync(); * ``` */ function cancelSync() { return __awaiter(this, void 0, void 0, function* () { return AccountBridge.cancelSync(); }); } exports.cancelSync = cancelSync;