UNPKG

@safient/core

Version:

JavaScript SDK to manage safes and interact with Safient protocol.

31 lines (30 loc) 1.47 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.thread = void 0; const hub_1 = require("@textile/hub"); const thread = (seed, apiKey, secret, threadID) => __awaiter(void 0, void 0, void 0, function* () { try { const identity = hub_1.PrivateKey.fromRawEd25519Seed(Uint8Array.from(seed)); const client = yield hub_1.Client.withKeyInfo({ key: apiKey, secret: secret, }, "wss://thread.safient.io"); yield client.getToken(identity); const threadId = hub_1.ThreadID.fromBytes(Uint8Array.from(threadID)); return { client, threadId }; } catch (err) { console.log(err); throw new Error("Error while creating threadData"); } }); exports.thread = thread;