@hamradio/meshcore 1.1.2 → 1.2.0
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 +55 -3
- package/dist/index.d.mts +137 -147
- package/dist/index.d.ts +137 -147
- package/dist/index.js +563 -249
- package/dist/index.mjs +558 -249
- package/dist/packet.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,14 +32,66 @@ _Packet {
|
|
|
32
32
|
routeType: 1,
|
|
33
33
|
payloadVersion: 0,
|
|
34
34
|
payloadType: 1,
|
|
35
|
-
pathHashCount:
|
|
36
|
-
pathHashSize:
|
|
35
|
+
pathHashCount: 10,
|
|
36
|
+
pathHashSize: 1,
|
|
37
37
|
pathHashBytes: 10,
|
|
38
|
-
pathHashes: [
|
|
38
|
+
pathHashes: [
|
|
39
|
+
'a5', '0e', '2c',
|
|
40
|
+
'b0', '33', '6d',
|
|
41
|
+
'b6', '7b', 'bf',
|
|
42
|
+
'78'
|
|
43
|
+
]
|
|
39
44
|
}
|
|
40
45
|
*/
|
|
41
46
|
```
|
|
42
47
|
|
|
48
|
+
## Packet structure parsing
|
|
49
|
+
|
|
50
|
+
The parser can also be instructed to generate a packet structure, useful for debugging or
|
|
51
|
+
printing packet details:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { Packet } from '@hamradio/meshcore';
|
|
55
|
+
|
|
56
|
+
const raw = new Uint8Array(Buffer.from("050AA50E2CB0336DB67BBF78928A3BB9BF7A8B677C83B6EC0716F9DD10002A06", "hex"));
|
|
57
|
+
const packet = Packet.fromBytes(raw);
|
|
58
|
+
const { structure } = packet.decode(true);
|
|
59
|
+
console.log(structure);
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
[
|
|
63
|
+
{
|
|
64
|
+
name: 'header',
|
|
65
|
+
data: Uint8Array(12) [
|
|
66
|
+
5, 10, 165, 14, 44,
|
|
67
|
+
176, 51, 109, 182, 123,
|
|
68
|
+
191, 120
|
|
69
|
+
],
|
|
70
|
+
fields: [
|
|
71
|
+
{ name: 'flags', type: 0, size: 1, bits: [Array] },
|
|
72
|
+
{ name: 'path length', type: 1, size: 1, bits: [Array] },
|
|
73
|
+
{ name: 'path hashes', type: 6, size: 10 }
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'response payload',
|
|
78
|
+
data: Uint8Array(20) [
|
|
79
|
+
146, 138, 59, 185, 191, 122,
|
|
80
|
+
139, 103, 124, 131, 182, 236,
|
|
81
|
+
7, 22, 249, 221, 16, 0,
|
|
82
|
+
42, 6
|
|
83
|
+
],
|
|
84
|
+
fields: [
|
|
85
|
+
{ name: 'destination hash', type: 1, size: 1, value: 146 },
|
|
86
|
+
{ name: 'source hash', type: 1, size: 1, value: 138 },
|
|
87
|
+
{ name: 'cipher MAC', type: 6, size: 2, value: [Uint8Array] },
|
|
88
|
+
{ name: 'cipher text', type: 6, size: 16, value: [Uint8Array] }
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
*/
|
|
93
|
+
```
|
|
94
|
+
|
|
43
95
|
## Identities
|
|
44
96
|
|
|
45
97
|
The package supports:
|
package/dist/index.d.mts
CHANGED
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
type NodeHash = number;
|
|
2
|
-
interface IIdentity {
|
|
3
|
-
hash(): NodeHash;
|
|
4
|
-
toString(): string;
|
|
5
|
-
verify(signature: Uint8Array, message: Uint8Array): boolean;
|
|
6
|
-
matches(other: IIdentity | IPublicKey | Uint8Array | string): boolean;
|
|
7
|
-
}
|
|
8
|
-
interface ILocalIdentity extends IIdentity {
|
|
9
|
-
sign(message: Uint8Array): Uint8Array;
|
|
10
|
-
calculateSharedSecret(other: IIdentity | IPublicKey): ISharedSecret;
|
|
11
|
-
}
|
|
12
|
-
interface IContact {
|
|
13
|
-
name: string;
|
|
14
|
-
identity: IIdentity;
|
|
15
|
-
calculateSharedSecret(me: ILocalIdentity): ISharedSecret;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type identity_types_IContact = IContact;
|
|
19
|
-
type identity_types_IIdentity = IIdentity;
|
|
20
|
-
type identity_types_ILocalIdentity = ILocalIdentity;
|
|
21
|
-
type identity_types_NodeHash = NodeHash;
|
|
22
|
-
declare namespace identity_types {
|
|
23
|
-
export type { identity_types_IContact as IContact, identity_types_IIdentity as IIdentity, identity_types_ILocalIdentity as ILocalIdentity, identity_types_NodeHash as NodeHash };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
1
|
interface IPublicKey {
|
|
27
2
|
toHash(): NodeHash;
|
|
28
3
|
toBytes(): Uint8Array;
|
|
@@ -49,53 +24,52 @@ interface IStaticSecret {
|
|
|
49
24
|
diffieHellman(otherPublicKey: IPublicKey): ISharedSecret;
|
|
50
25
|
}
|
|
51
26
|
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
type crypto_types_IStaticSecret = IStaticSecret;
|
|
56
|
-
declare namespace crypto_types {
|
|
57
|
-
export type { crypto_types_IPrivateKey as IPrivateKey, crypto_types_IPublicKey as IPublicKey, crypto_types_ISharedSecret as ISharedSecret, crypto_types_IStaticSecret as IStaticSecret };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
declare class PublicKey implements IPublicKey {
|
|
61
|
-
key: Uint8Array;
|
|
62
|
-
constructor(key: Uint8Array | string);
|
|
63
|
-
toHash(): NodeHash;
|
|
64
|
-
toBytes(): Uint8Array;
|
|
27
|
+
type NodeHash = number;
|
|
28
|
+
interface IIdentity {
|
|
29
|
+
hash(): NodeHash;
|
|
65
30
|
toString(): string;
|
|
66
|
-
|
|
67
|
-
|
|
31
|
+
verify(signature: Uint8Array, message: Uint8Array): boolean;
|
|
32
|
+
matches(other: IIdentity | IPublicKey | Uint8Array | string): boolean;
|
|
68
33
|
}
|
|
69
|
-
|
|
70
|
-
private secretKey;
|
|
71
|
-
private publicKey;
|
|
72
|
-
constructor(seed: Uint8Array | string);
|
|
73
|
-
toPublicKey(): PublicKey;
|
|
74
|
-
toBytes(): Uint8Array;
|
|
75
|
-
toString(): string;
|
|
34
|
+
interface ILocalIdentity extends IIdentity {
|
|
76
35
|
sign(message: Uint8Array): Uint8Array;
|
|
77
|
-
calculateSharedSecret(other:
|
|
78
|
-
static generate(): PrivateKey;
|
|
36
|
+
calculateSharedSecret(other: IIdentity | IPublicKey): ISharedSecret;
|
|
79
37
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
toBytes(): Uint8Array;
|
|
85
|
-
toString(): string;
|
|
86
|
-
decrypt(hmac: Uint8Array, ciphertext: Uint8Array): Uint8Array;
|
|
87
|
-
encrypt(data: Uint8Array): {
|
|
88
|
-
hmac: Uint8Array;
|
|
89
|
-
ciphertext: Uint8Array;
|
|
90
|
-
};
|
|
91
|
-
private calculateHmac;
|
|
92
|
-
static fromName(name: string): SharedSecret;
|
|
38
|
+
interface IContact {
|
|
39
|
+
name: string;
|
|
40
|
+
identity: IIdentity;
|
|
41
|
+
calculateSharedSecret(me: ILocalIdentity): ISharedSecret;
|
|
93
42
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
43
|
+
|
|
44
|
+
declare enum FieldType {
|
|
45
|
+
BITS = 0,
|
|
46
|
+
UINT8 = 1,
|
|
47
|
+
UINT16_LE = 2,
|
|
48
|
+
UINT16_BE = 3,
|
|
49
|
+
UINT32_LE = 4,
|
|
50
|
+
UINT32_BE = 5,
|
|
51
|
+
BYTES = 6,// 8-bits per value
|
|
52
|
+
WORDS = 7,// 16-bits per value
|
|
53
|
+
DWORDS = 8,// 32-bits per value
|
|
54
|
+
QWORDS = 9,// 64-bits per value
|
|
55
|
+
C_STRING = 10
|
|
56
|
+
}
|
|
57
|
+
type PacketStructure = PacketSegment[];
|
|
58
|
+
interface PacketSegment {
|
|
59
|
+
name: string;
|
|
60
|
+
data: Uint8Array;
|
|
61
|
+
fields: PacketField[];
|
|
62
|
+
}
|
|
63
|
+
interface PacketField {
|
|
64
|
+
type: FieldType;
|
|
65
|
+
size: number;
|
|
66
|
+
name?: string;
|
|
67
|
+
bits?: PacketFieldBit[];
|
|
68
|
+
value?: any;
|
|
69
|
+
}
|
|
70
|
+
interface PacketFieldBit {
|
|
71
|
+
name: string;
|
|
72
|
+
size: number;
|
|
99
73
|
}
|
|
100
74
|
|
|
101
75
|
type Uint16 = number;
|
|
@@ -105,7 +79,10 @@ interface IPacket {
|
|
|
105
79
|
pathLength: number;
|
|
106
80
|
path: Uint8Array;
|
|
107
81
|
payload: Uint8Array;
|
|
108
|
-
decode(): Payload
|
|
82
|
+
decode(withStructure?: boolean): Payload | {
|
|
83
|
+
payload: Payload;
|
|
84
|
+
structure: PacketStructure;
|
|
85
|
+
};
|
|
109
86
|
}
|
|
110
87
|
declare enum RouteType {
|
|
111
88
|
TRANSPORT_FLOOD = 0,
|
|
@@ -126,12 +103,15 @@ declare enum PayloadType {
|
|
|
126
103
|
TRACE = 9,
|
|
127
104
|
RAW_CUSTOM = 15
|
|
128
105
|
}
|
|
129
|
-
type Payload = RequestPayload | ResponsePayload | TextPayload | AckPayload | AdvertPayload | GroupTextPayload | GroupDataPayload | AnonReqPayload | PathPayload | TracePayload | RawCustomPayload;
|
|
106
|
+
type Payload = BasePayload & (RequestPayload | ResponsePayload | TextPayload | AckPayload | AdvertPayload | GroupTextPayload | GroupDataPayload | AnonReqPayload | PathPayload | TracePayload | RawCustomPayload);
|
|
107
|
+
interface BasePayload {
|
|
108
|
+
type: PayloadType;
|
|
109
|
+
}
|
|
130
110
|
interface EncryptedPayload {
|
|
131
111
|
cipherMAC: Uint8Array;
|
|
132
112
|
cipherText: Uint8Array;
|
|
133
113
|
}
|
|
134
|
-
interface RequestPayload {
|
|
114
|
+
interface RequestPayload extends BasePayload {
|
|
135
115
|
type: PayloadType.REQUEST;
|
|
136
116
|
dst: NodeHash;
|
|
137
117
|
src: NodeHash;
|
|
@@ -152,7 +132,7 @@ interface DecryptedRequest {
|
|
|
152
132
|
requestType: RequestType;
|
|
153
133
|
requestData: Uint8Array;
|
|
154
134
|
}
|
|
155
|
-
interface ResponsePayload {
|
|
135
|
+
interface ResponsePayload extends BasePayload {
|
|
156
136
|
type: PayloadType.RESPONSE;
|
|
157
137
|
dst: NodeHash;
|
|
158
138
|
src: NodeHash;
|
|
@@ -163,7 +143,7 @@ interface DecryptedResponse {
|
|
|
163
143
|
timestamp: Date;
|
|
164
144
|
responseData: Uint8Array;
|
|
165
145
|
}
|
|
166
|
-
interface TextPayload {
|
|
146
|
+
interface TextPayload extends BasePayload {
|
|
167
147
|
type: PayloadType.TEXT;
|
|
168
148
|
dst: NodeHash;
|
|
169
149
|
src: NodeHash;
|
|
@@ -181,11 +161,11 @@ interface DecryptedText {
|
|
|
181
161
|
attempt: number;
|
|
182
162
|
message: string;
|
|
183
163
|
}
|
|
184
|
-
interface AckPayload {
|
|
164
|
+
interface AckPayload extends BasePayload {
|
|
185
165
|
type: PayloadType.ACK;
|
|
186
166
|
checksum: Uint8Array;
|
|
187
167
|
}
|
|
188
|
-
interface AdvertPayload {
|
|
168
|
+
interface AdvertPayload extends BasePayload {
|
|
189
169
|
type: PayloadType.ADVERT;
|
|
190
170
|
publicKey: Uint8Array;
|
|
191
171
|
timestamp: Date;
|
|
@@ -209,7 +189,7 @@ interface AdvertAppData {
|
|
|
209
189
|
hasName: boolean;
|
|
210
190
|
name?: string;
|
|
211
191
|
}
|
|
212
|
-
interface GroupTextPayload {
|
|
192
|
+
interface GroupTextPayload extends BasePayload {
|
|
213
193
|
type: PayloadType.GROUP_TEXT;
|
|
214
194
|
channelHash: NodeHash;
|
|
215
195
|
encrypted: EncryptedPayload;
|
|
@@ -221,7 +201,7 @@ interface DecryptedGroupText {
|
|
|
221
201
|
attempt: number;
|
|
222
202
|
message: string;
|
|
223
203
|
}
|
|
224
|
-
interface GroupDataPayload {
|
|
204
|
+
interface GroupDataPayload extends BasePayload {
|
|
225
205
|
type: PayloadType.GROUP_DATA;
|
|
226
206
|
channelHash: NodeHash;
|
|
227
207
|
encrypted: EncryptedPayload;
|
|
@@ -231,7 +211,7 @@ interface DecryptedGroupData {
|
|
|
231
211
|
timestamp: Date;
|
|
232
212
|
data: Uint8Array;
|
|
233
213
|
}
|
|
234
|
-
interface AnonReqPayload {
|
|
214
|
+
interface AnonReqPayload extends BasePayload {
|
|
235
215
|
type: PayloadType.ANON_REQ;
|
|
236
216
|
dst: NodeHash;
|
|
237
217
|
publicKey: Uint8Array;
|
|
@@ -242,57 +222,99 @@ interface DecryptedAnonReq {
|
|
|
242
222
|
timestamp: Date;
|
|
243
223
|
data: Uint8Array;
|
|
244
224
|
}
|
|
245
|
-
interface PathPayload {
|
|
225
|
+
interface PathPayload extends BasePayload {
|
|
246
226
|
type: PayloadType.PATH;
|
|
247
227
|
dst: NodeHash;
|
|
248
228
|
src: NodeHash;
|
|
249
229
|
}
|
|
250
|
-
interface TracePayload {
|
|
230
|
+
interface TracePayload extends BasePayload {
|
|
251
231
|
type: PayloadType.TRACE;
|
|
252
232
|
tag: number;
|
|
253
233
|
authCode: number;
|
|
254
234
|
flags: number;
|
|
255
235
|
nodes: Uint8Array;
|
|
256
236
|
}
|
|
257
|
-
interface RawCustomPayload {
|
|
237
|
+
interface RawCustomPayload extends BasePayload {
|
|
258
238
|
type: PayloadType.RAW_CUSTOM;
|
|
259
239
|
data: Uint8Array;
|
|
260
240
|
}
|
|
261
241
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
242
|
+
declare class Packet implements IPacket {
|
|
243
|
+
header: number;
|
|
244
|
+
pathLength: number;
|
|
245
|
+
path: Uint8Array;
|
|
246
|
+
payload: Uint8Array;
|
|
247
|
+
transport?: [number, number];
|
|
248
|
+
routeType: RouteType;
|
|
249
|
+
payloadVersion: number;
|
|
250
|
+
payloadType: PayloadType;
|
|
251
|
+
pathHashCount: number;
|
|
252
|
+
pathHashSize: number;
|
|
253
|
+
pathHashBytes: number;
|
|
254
|
+
pathHashes: string[];
|
|
255
|
+
structure?: PacketStructure | undefined;
|
|
256
|
+
constructor(header: number, transport: [number, number] | undefined, pathLength: number, path: Uint8Array, payload: Uint8Array);
|
|
257
|
+
static fromBytes(bytes: Uint8Array | string): Packet;
|
|
258
|
+
static hasTransportCodes(routeType: RouteType): boolean;
|
|
259
|
+
hash(): string;
|
|
260
|
+
private ensureStructure;
|
|
261
|
+
decode(withStructure?: boolean): Payload | {
|
|
262
|
+
payload: Payload;
|
|
263
|
+
structure: PacketStructure;
|
|
264
|
+
};
|
|
265
|
+
private decodeEncryptedPayload;
|
|
266
|
+
private decodeRequest;
|
|
267
|
+
private decodeResponse;
|
|
268
|
+
private decodeText;
|
|
269
|
+
private decodeAck;
|
|
270
|
+
private decodeAdvert;
|
|
271
|
+
private decodeGroupText;
|
|
272
|
+
private decodeGroupData;
|
|
273
|
+
private decodeAnonReq;
|
|
274
|
+
private decodePath;
|
|
275
|
+
private decodeTrace;
|
|
276
|
+
private decodeRawCustom;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
declare class PublicKey implements IPublicKey {
|
|
280
|
+
key: Uint8Array;
|
|
281
|
+
constructor(key: Uint8Array | string);
|
|
282
|
+
toHash(): NodeHash;
|
|
283
|
+
toBytes(): Uint8Array;
|
|
284
|
+
toString(): string;
|
|
285
|
+
equals(other: PublicKey | Uint8Array | string): boolean;
|
|
286
|
+
verify(message: Uint8Array, signature: Uint8Array): boolean;
|
|
287
|
+
}
|
|
288
|
+
declare class PrivateKey {
|
|
289
|
+
private secretKey;
|
|
290
|
+
private publicKey;
|
|
291
|
+
constructor(seed: Uint8Array | string);
|
|
292
|
+
toPublicKey(): PublicKey;
|
|
293
|
+
toBytes(): Uint8Array;
|
|
294
|
+
toString(): string;
|
|
295
|
+
sign(message: Uint8Array): Uint8Array;
|
|
296
|
+
calculateSharedSecret(other: PublicKey | Uint8Array | string): Uint8Array;
|
|
297
|
+
static generate(): PrivateKey;
|
|
298
|
+
}
|
|
299
|
+
declare class SharedSecret implements ISharedSecret {
|
|
300
|
+
private secret;
|
|
301
|
+
constructor(secret: Uint8Array);
|
|
302
|
+
toHash(): NodeHash;
|
|
303
|
+
toBytes(): Uint8Array;
|
|
304
|
+
toString(): string;
|
|
305
|
+
decrypt(hmac: Uint8Array, ciphertext: Uint8Array): Uint8Array;
|
|
306
|
+
encrypt(data: Uint8Array): {
|
|
307
|
+
hmac: Uint8Array;
|
|
308
|
+
ciphertext: Uint8Array;
|
|
309
|
+
};
|
|
310
|
+
private calculateHmac;
|
|
311
|
+
static fromName(name: string): SharedSecret;
|
|
312
|
+
}
|
|
313
|
+
declare class StaticSecret implements IStaticSecret {
|
|
314
|
+
private secret;
|
|
315
|
+
constructor(secret: Uint8Array | string);
|
|
316
|
+
publicKey(): IPublicKey;
|
|
317
|
+
diffieHellman(otherPublicKey: IPublicKey): SharedSecret;
|
|
296
318
|
}
|
|
297
319
|
|
|
298
320
|
declare const parseNodeHash: (hash: NodeHash | string | Uint8Array) => NodeHash;
|
|
@@ -357,36 +379,4 @@ declare class Contacts {
|
|
|
357
379
|
};
|
|
358
380
|
}
|
|
359
381
|
|
|
360
|
-
|
|
361
|
-
header: number;
|
|
362
|
-
pathLength: number;
|
|
363
|
-
path: Uint8Array;
|
|
364
|
-
payload: Uint8Array;
|
|
365
|
-
transport?: [number, number];
|
|
366
|
-
routeType: RouteType;
|
|
367
|
-
payloadVersion: number;
|
|
368
|
-
payloadType: PayloadType;
|
|
369
|
-
pathHashCount: number;
|
|
370
|
-
pathHashSize: number;
|
|
371
|
-
pathHashBytes: number;
|
|
372
|
-
pathHashes: string[];
|
|
373
|
-
constructor(header: number, transport: [number, number] | undefined, pathLength: number, path: Uint8Array, payload: Uint8Array);
|
|
374
|
-
static fromBytes(bytes: Uint8Array | string): Packet;
|
|
375
|
-
static hasTransportCodes(routeType: RouteType): boolean;
|
|
376
|
-
hash(): string;
|
|
377
|
-
decode(): Payload;
|
|
378
|
-
private decodeEncryptedPayload;
|
|
379
|
-
private decodeRequest;
|
|
380
|
-
private decodeResponse;
|
|
381
|
-
private decodeText;
|
|
382
|
-
private decodeAck;
|
|
383
|
-
private decodeAdvert;
|
|
384
|
-
private decodeGroupText;
|
|
385
|
-
private decodeGroupData;
|
|
386
|
-
private decodeAnonReq;
|
|
387
|
-
private decodePath;
|
|
388
|
-
private decodeTrace;
|
|
389
|
-
private decodeRawCustom;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
export { Contact, Contacts, Group, Identity, LocalIdentity, Packet, PrivateKey, PublicKey, SharedSecret, StaticSecret, crypto_types as cryptoTypes, crypto_types as cryptoTypesTypes, identity_types as identityTypes, identity_types as identityTypesTypes, packet_types as packetTypes, packet_types as packetTypesTypes, parseNodeHash };
|
|
382
|
+
export { type AckPayload, type AdvertPayload, type AnonReqPayload, Contact, Contacts, type EncryptedPayload, Group, type GroupDataPayload, type GroupTextPayload, type IContact, type IIdentity, type ILocalIdentity, type IPacket, type IPrivateKey, type IPublicKey, type ISharedSecret, type IStaticSecret, Identity, LocalIdentity, type NodeHash, NodeType, Packet, type PathPayload, type Payload, PayloadType, PrivateKey, PublicKey, type RawCustomPayload, type RequestPayload, RequestType, type ResponsePayload, RouteType, SharedSecret, StaticSecret, type TextPayload, TextType, type TracePayload, parseNodeHash };
|