esm syntax changes

This commit is contained in:
2021-05-26 13:51:53 -05:00
parent 43a3dbd582
commit 67abe2abc2
6 changed files with 15 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
import { randomBytes } from 'crypto';
import { Int64BE, Uint64BE } from 'int64-buffer';
import { sha256 } from 'js-sha256';
import { TextEncoder } from 'text-encoding';
import {Int64BE, Uint64BE} from 'int64-buffer';
import crypto from 'crypto';
import {TextEncoder} from 'text-encoding';
import {
be_ui8_array_to_i16,
@@ -158,10 +158,10 @@ export default class packet {
decrypt = async () => {
try {
const hash = sha256.create();
hash.update(new TextEncoder().encode(this.token));
let hash = crypto.createHash('sha256');
hash = hash.update(new TextEncoder().encode(this.token));
const key = Uint8Array.from(hash.array());
const key = Uint8Array.from(hash.digest());
const nonce = this.buffer.slice(0, 12);
this.buffer = new JSChaCha20(key, nonce, 0).decrypt(
@@ -270,10 +270,10 @@ export default class packet {
encrypt = async (nonce) => {
try {
this.push_buffer(packet.HEADER);
const hash = sha256.create();
hash.update(new TextEncoder().encode(this.token));
let hash = crypto.createHash('sha256');
hash = hash.update(new TextEncoder().encode(this.token));
const key = Uint8Array.from(hash.array());
const key = Uint8Array.from(hash.digest());
if (!nonce) {
nonce = Uint8Array.from(randomBytes(12));
}