Socket
Socket
Sign inDemoInstall

@huskiesio/bot

Package Overview
Dependencies
257
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.4 to 0.2.5

23

dts/chat/HCBotChat.d.ts

@@ -7,9 +7,10 @@ /**

*/
/// <reference types="node" />
import { IHCBotChatHistory, IHCBotThread } from "../types";
import { Socket } from "../HuskyChatBot";
import { HCBotKeyManager } from "..";
import { IHCAPIThread } from "@huskiesio/types";
export declare type HCBotChatOnReceivedParam = {
threadId: string;
senderId: string;
payload: Buffer;
payload: string;
timestamp: number;

@@ -19,8 +20,7 @@ };

threadId: string;
senderId: string;
payload: Buffer;
payload: string;
timestamp: number;
};
export declare type HCBotChatOnReceivedHandler = (message: HCBotChatOnReceivedParam) => Promise<void>;
export declare type HCBotChatOnSentHandler = (message: HCBotChatOnSentParam) => Promise<void>;
export declare type HCBotChatOnReceivedHandler = (message: HCBotChatOnReceivedParam) => Promise<boolean>;
export declare type HCBotChatOnSentHandler = (message: HCBotChatOnSentParam) => Promise<boolean>;
export declare class HCBotChat {

@@ -31,3 +31,5 @@ private readonly _history;

private _onThreadUpdated;
constructor(socket: Socket);
private socket;
private userKeyManager;
constructor(socket: Socket, userKeyManager: HCBotKeyManager);
history(): IHCBotChatHistory;

@@ -38,7 +40,8 @@ onReceived(handler: HCBotChatOnReceivedHandler): void;

threads(): Promise<IHCBotThread[]>;
send(thread: (string | IHCBotThread), payload: string): Promise<string>;
send(threadId: string, payload: string): Promise<void>;
createThread(name: string, description: string, members: string[]): Promise<string>;
handleChatMessageReceived(message: HCBotChatOnReceivedParam): Promise<void>;
handleChatMessageSent(message: HCBotChatOnSentParam): Promise<void>;
handleThreadUpdated(threadId: string): Promise<void>;
getThreadForId(threadId: string): Promise<IHCBotThread>;
handleThreadUpdated(threadId: string): Promise<boolean>;
getThreadForId(threadId: string): Promise<IHCAPIThread | undefined>;
}

@@ -24,2 +24,4 @@ /**

private constructor();
private handleChatMessageReceived;
private handleChatMessageSent;
chat(): HCBotChat;

@@ -37,5 +39,5 @@ directory(): HCBotDirectory;

}): Promise<string>;
static signUpFinish(code: string, token: string): Promise<string>;
static signIn(username: string, password: string, deviceId: string): Promise<HuskyChatBot>;
static signUpFinish(code: string, token: string): Promise<void>;
static signIn(username: string, password: string): Promise<HuskyChatBot>;
}
export {};

@@ -9,5 +9,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const krypton_1 = require("@element-ts/krypton");
class HCBotChat {
constructor(socket) {
constructor(socket, userKeyManager) {
this._history = {};
this.socket = socket;
this.userKeyManager = userKeyManager;
}

@@ -19,3 +22,17 @@ history() { return this._history; }

async threads() { return []; }
async send(thread, payload) { return ""; }
async send(threadId, payload) {
const payloadData = Buffer.from(payload, "utf8");
const keys = await this.socket.invoke("chat thread keys", threadId);
const encryptedPayload = {};
for (const userId of Object.keys(keys)) {
const userPublicKeyString = keys[userId];
const userPublicKeyData = Buffer.from(userPublicKeyString, "hex");
const encryptedPayloadForUser = krypton_1.KrRSA.encrypt(payloadData, userPublicKeyData);
encryptedPayload[userId] = encryptedPayloadForUser.toString("hex");
}
await this.socket.invoke("chat send", { threadId, payload: encryptedPayload });
}
async createThread(name, description, members) {
return await this.socket.invoke("chat thread create", { name, description, members });
}
async handleChatMessageReceived(message) {

@@ -32,6 +49,9 @@ if (this._onReceived)

this._onThreadUpdated(threadId);
return true;
}
async getThreadForId(threadId) { return {}; }
async getThreadForId(threadId) {
return await this.socket.invoke("chat thread", threadId);
}
}
exports.HCBotChat = HCBotChat;
//# sourceMappingURL=HCBotChat.js.map

@@ -16,2 +16,3 @@ "use strict";

const HCBotKeyManager_1 = require("./managers/HCBotKeyManager");
const HCBotFileManager_1 = require("./managers/HCBotFileManager");
class HuskyChatBot {

@@ -22,6 +23,28 @@ constructor(socket) {

this.socket = socket;
this._chat = new HCBotChat_1.HCBotChat(socket);
this._chat = new HCBotChat_1.HCBotChat(socket, this.userKeyManager);
this._directory = new HCBotDirectory_1.HCBotDirectory(socket);
this._info = new HCBotInfo_1.HCBotInfo(socket);
}
async handleChatMessageReceived(message) {
const messagePayload = message.payload;
const messagePayloadData = Buffer.from(messagePayload, "hex");
const privateKey = this.userKeyManager.private();
const messageDecrypted = krypton_1.KrRSA.decrypt(messagePayloadData, privateKey);
const messageDecryptedString = messageDecrypted.toString("utf8");
console.log(messageDecryptedString);
message.payload = messageDecryptedString;
await this._chat.handleChatMessageReceived(message);
return true;
}
async handleChatMessageSent(message) {
const messagePayload = message.payload;
const messagePayloadData = Buffer.from(messagePayload, "hex");
const privateKey = this.userKeyManager.private();
const messageDecrypted = krypton_1.KrRSA.decrypt(messagePayloadData, privateKey);
const messageDecryptedString = messageDecrypted.toString("utf8");
console.log(messageDecryptedString);
message.payload = messageDecryptedString;
await this._chat.handleChatMessageSent(message);
return true;
}
chat() { return this._chat; }

@@ -35,4 +58,4 @@ directory() { return this._directory; }

const bot = new HuskyChatBot(socket);
commandRegistry.addCommand("chat message received", bot._chat.handleChatMessageReceived);
commandRegistry.addCommand("chat message sent", bot._chat.handleChatMessageSent);
commandRegistry.addCommand("chat message received", bot.handleChatMessageReceived);
commandRegistry.addCommand("chat message sent", bot.handleChatMessageSent);
commandRegistry.addCommand("thread updated", bot._chat.handleThreadUpdated);

@@ -57,6 +80,12 @@ return bot;

const socket = await node_client_1.CommandSocket.create(this.SOCKET_ADDRESS);
return await socket.invoke("signUp finish", { code, token });
const deviceId = await socket.invoke("signUp finish", { code, token });
const deviceIdData = Buffer.from(deviceId);
HCBotFileManager_1.HCBotFileManager.save("deviceId", deviceIdData);
}
static async signIn(username, password, deviceId) {
static async signIn(username, password) {
const bot = await HuskyChatBot.init();
const deviceIdData = HCBotFileManager_1.HCBotFileManager.get("deviceId");
if (deviceIdData === undefined)
throw new Error("deviceId file not found. Sign up again...");
const deviceId = deviceIdData.toString("hex");
const dataToSignString = await bot.socket.invoke("signIn start", { username, password, deviceId });

@@ -63,0 +92,0 @@ const dataToSign = Buffer.from(dataToSignString, "hex");

@@ -19,6 +19,4 @@ "use strict";

// console.log(token);
// const deviceId: string = await HuskyChatBot.signUpFinish("B2A85D", "5e5238f32f9f3078c5a9301a");
// console.log(deviceId);
const deviceId = "5e5239092f9f3078c5a9301c";
const bot = await index_1.HuskyChatBot.signIn("ejcobb", "alpine", deviceId);
// await HuskyChatBot.signUpFinish("B2A85D", "5e5238f32f9f3078c5a9301a");
const bot = await index_1.HuskyChatBot.signIn("ejcobb", "alpine");
console.log(await bot.info().me().firstName());

@@ -25,0 +23,0 @@ console.log(await bot.info().me().lastName());

{
"name": "@huskiesio/bot",
"version": "0.2.4",
"version": "0.2.5",
"description": "A package to build a bot for the huskies.io chat application.",

@@ -5,0 +5,0 @@ "keywords": [],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc