@hamradio/meshcore 1.1.1 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,18 +2,54 @@
2
2
 
3
3
  TypeScript library for MeshCore protocol utilities.
4
4
 
5
- Quick start
5
+ ## Packet parsing
6
6
 
7
- 1. Install dev dependencies:
7
+ Using the library to decode MeshCore packets:
8
8
 
9
- ```bash
10
- npm install --save-dev typescript tsup
11
- ```
9
+ ```ts
10
+ import { Packet } from '@hamradio/meshcore';
12
11
 
13
- 2. Build the library:
12
+ const raw = new Uint8Array(Buffer.from("050AA50E2CB0336DB67BBF78928A3BB9BF7A8B677C83B6EC0716F9DD10002A06", "hex"));
13
+ const packet = Packet.fromBytes(raw);
14
+ console.log(packet);
14
15
 
15
- ```bash
16
- npm run build
16
+ /*
17
+ _Packet {
18
+ header: 5,
19
+ transport: undefined,
20
+ pathLength: 10,
21
+ path: Uint8Array(10) [
22
+ 165, 14, 44, 176,
23
+ 51, 109, 182, 123,
24
+ 191, 120
25
+ ],
26
+ payload: Uint8Array(20) [
27
+ 146, 138, 59, 185, 191, 122,
28
+ 139, 103, 124, 131, 182, 236,
29
+ 7, 22, 249, 221, 16, 0,
30
+ 42, 6
31
+ ],
32
+ routeType: 1,
33
+ payloadVersion: 0,
34
+ payloadType: 1,
35
+ pathHashCount: 10,
36
+ pathHashSize: 1,
37
+ pathHashBytes: 10,
38
+ pathHashes: [
39
+ 'a5', '0e', '2c',
40
+ 'b0', '33', '6d',
41
+ 'b6', '7b', 'bf',
42
+ '78'
43
+ ]
44
+ }
45
+ */
17
46
  ```
18
47
 
19
- 3. Use the build output from the `dist/` folder or publish to npm.
48
+ ## Identities
49
+
50
+ The package supports:
51
+ - `Identity` for public key management.
52
+ - `LocalIdentity` for private key management.
53
+ - `Contact` for managing named identities.
54
+ - `Group` for managing groups.
55
+ - `KeyManager` for managing all of the above and handling decryption.
package/dist/index.js CHANGED
@@ -626,12 +626,12 @@ var Packet = class _Packet {
626
626
  this.routeType = header & 3;
627
627
  this.payloadVersion = header >> 6 & 3;
628
628
  this.payloadType = header >> 2 & 15;
629
- this.pathHashCount = (pathLength >> 6) + 1;
630
- this.pathHashSize = pathLength & 63;
629
+ this.pathHashSize = (pathLength >> 6) + 1;
630
+ this.pathHashCount = pathLength & 63;
631
631
  this.pathHashBytes = this.pathHashCount * this.pathHashSize;
632
632
  this.pathHashes = [];
633
- for (let i = 0; i < this.pathHashCount; i++) {
634
- const hashBytes = this.path.slice(i * this.pathHashSize, (i + 1) * this.pathHashSize);
633
+ for (let i = 0; i < this.pathHashBytes; i += this.pathHashSize) {
634
+ const hashBytes = this.path.slice(i, i + this.pathHashSize);
635
635
  const hashHex = (0, import_utils2.bytesToHex)(hashBytes);
636
636
  this.pathHashes.push(hashHex);
637
637
  }
package/dist/index.mjs CHANGED
@@ -590,12 +590,12 @@ var Packet = class _Packet {
590
590
  this.routeType = header & 3;
591
591
  this.payloadVersion = header >> 6 & 3;
592
592
  this.payloadType = header >> 2 & 15;
593
- this.pathHashCount = (pathLength >> 6) + 1;
594
- this.pathHashSize = pathLength & 63;
593
+ this.pathHashSize = (pathLength >> 6) + 1;
594
+ this.pathHashCount = pathLength & 63;
595
595
  this.pathHashBytes = this.pathHashCount * this.pathHashSize;
596
596
  this.pathHashes = [];
597
- for (let i = 0; i < this.pathHashCount; i++) {
598
- const hashBytes = this.path.slice(i * this.pathHashSize, (i + 1) * this.pathHashSize);
597
+ for (let i = 0; i < this.pathHashBytes; i += this.pathHashSize) {
598
+ const hashBytes = this.path.slice(i, i + this.pathHashSize);
599
599
  const hashHex = bytesToHex(hashBytes);
600
600
  this.pathHashes.push(hashHex);
601
601
  }
package/dist/packet.js CHANGED
@@ -11,12 +11,12 @@ export class Packet {
11
11
  this.routeType = (header) & 0x03;
12
12
  this.payloadVersion = (header >> 6) & 0x03;
13
13
  this.payloadType = (header >> 2) & 0x0f;
14
- this.pathHashCount = (pathLength >> 6) + 1;
15
- this.pathHashSize = pathLength & 0x3f;
14
+ this.pathHashSize = (pathLength >> 6) + 1;
15
+ this.pathHashCount = pathLength & 0x3f;
16
16
  this.pathHashBytes = this.pathHashCount * this.pathHashSize;
17
17
  this.pathHashes = [];
18
- for (let i = 0; i < this.pathHashCount; i++) {
19
- const hashBytes = this.path.slice(i * this.pathHashSize, (i + 1) * this.pathHashSize);
18
+ for (let i = 0; i < this.pathHashBytes; i += this.pathHashSize) {
19
+ const hashBytes = this.path.slice(i, i + this.pathHashSize);
20
20
  const hashHex = bytesToHex(hashBytes);
21
21
  this.pathHashes.push(hashHex);
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamradio/meshcore",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "MeshCore protocol support for Typescript",
5
5
  "keywords": [
6
6
  "MeshCore",
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git+https://git.maze.io/ham/meshcore.js"
12
+ "url": "https://git.maze.io/ham/meshcore.js"
13
13
  },
14
14
  "license": "MIT",
15
15
  "author": "Wijnand Modderman-Lenstra",