esm syntax changes
This commit is contained in:
@@ -55,7 +55,7 @@ also be set to a strong, random password.
|
||||
## Example API Usage
|
||||
|
||||
```javascript
|
||||
const rep = require('@blockstorage/repertory-js');
|
||||
import * as rep from 'repertory-js';
|
||||
|
||||
|
||||
// Repertory host settings
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"altcoin",
|
||||
"cryptocurrency"
|
||||
],
|
||||
"main": "dist/mjs/repertory-js.mjs",
|
||||
"module": "dist/mjs/repertory-js.mjs",
|
||||
"files": [
|
||||
"dist/mjs"
|
||||
@@ -34,7 +35,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"int64-buffer": "^1.0.0",
|
||||
"js-sha256": "^0.9.0",
|
||||
"socket-pool": "^1.2.3",
|
||||
"text-encoding": "^0.7.0",
|
||||
"uuid": "^8.3.2"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import connection from '../networking/connection';
|
||||
import packet from '../networking/packet';
|
||||
|
||||
const Socket = require('net');
|
||||
import Socket from 'net';
|
||||
|
||||
test(`connect fails when error occurs during createConnection`, async () => {
|
||||
const mock_create = (port, host, cb) => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {get_version, instance_id, package_json} from '../utils/constants';
|
||||
|
||||
const uuid = require('uuid');
|
||||
import * as uuid from 'uuid';
|
||||
|
||||
test(`can read 'package.json'`, () => {
|
||||
console.log(package_json);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomBytes } from 'crypto';
|
||||
import {Int64BE, Uint64BE} from 'int64-buffer';
|
||||
import { sha256 } from 'js-sha256';
|
||||
import crypto from 'crypto';
|
||||
import {TextEncoder} from 'text-encoding';
|
||||
|
||||
import {
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
import _package_json from '../../package.json';
|
||||
|
||||
export const instance_id = uuidv4();
|
||||
|
||||
Reference in New Issue
Block a user