Improve library
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { encrypt } from "romulus-js";
|
||||
import { encrypt, decrypt } from "romulus-js";
|
||||
import { DEFAULT_KEY, MessageTypes } from "../common";
|
||||
import { numberToUint16BE } from "../utilities/number";
|
||||
import { packOutgoingPacket } from "./packet";
|
||||
@@ -28,9 +28,17 @@ export function packBasicMessage(
|
||||
|
||||
/**
|
||||
* Unpack the data section of an incoming basic message (0x0001) message.
|
||||
* @param data The data section of an incoming basic message (0x0001) message.
|
||||
* @returns An encrypted unpacked basic message (0x0001) message.
|
||||
* @param data The encrypted data section of an incoming basic message (0x0001) message.
|
||||
* @param key The key to decrypt the data with.
|
||||
* @returns The decrypted plaintext message.
|
||||
*/
|
||||
export function unpackBasicMessage(data: Uint8Array): Uint8Array {
|
||||
return data;
|
||||
export function unpackBasicMessage(
|
||||
data: Uint8Array,
|
||||
key: Uint8Array = DEFAULT_KEY,
|
||||
): Uint8Array {
|
||||
const result = decrypt(data, MESSAGE_TYPE, key);
|
||||
if (result.success) {
|
||||
return result.plaintext;
|
||||
}
|
||||
throw new Error("Failed to decrypt basic message");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user