@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/dist/index.d.ts 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 crypto_types_IPrivateKey = IPrivateKey;
53
- type crypto_types_IPublicKey = IPublicKey;
54
- type crypto_types_ISharedSecret = ISharedSecret;
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
- equals(other: PublicKey | Uint8Array | string): boolean;
67
- verify(message: Uint8Array, signature: Uint8Array): boolean;
31
+ verify(signature: Uint8Array, message: Uint8Array): boolean;
32
+ matches(other: IIdentity | IPublicKey | Uint8Array | string): boolean;
68
33
  }
69
- declare class PrivateKey {
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: PublicKey | Uint8Array | string): Uint8Array;
78
- static generate(): PrivateKey;
36
+ calculateSharedSecret(other: IIdentity | IPublicKey): ISharedSecret;
79
37
  }
80
- declare class SharedSecret implements ISharedSecret {
81
- private secret;
82
- constructor(secret: Uint8Array);
83
- toHash(): NodeHash;
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
- declare class StaticSecret implements IStaticSecret {
95
- private secret;
96
- constructor(secret: Uint8Array | string);
97
- publicKey(): IPublicKey;
98
- diffieHellman(otherPublicKey: IPublicKey): SharedSecret;
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
- type packet_types_AckPayload = AckPayload;
263
- type packet_types_AdvertAppData = AdvertAppData;
264
- type packet_types_AdvertPayload = AdvertPayload;
265
- type packet_types_AnonReqPayload = AnonReqPayload;
266
- type packet_types_DecryptedAnonReq = DecryptedAnonReq;
267
- type packet_types_DecryptedGroupData = DecryptedGroupData;
268
- type packet_types_DecryptedGroupText = DecryptedGroupText;
269
- type packet_types_DecryptedRequest = DecryptedRequest;
270
- type packet_types_DecryptedResponse = DecryptedResponse;
271
- type packet_types_DecryptedText = DecryptedText;
272
- type packet_types_EncryptedPayload = EncryptedPayload;
273
- type packet_types_GroupDataPayload = GroupDataPayload;
274
- type packet_types_GroupTextPayload = GroupTextPayload;
275
- type packet_types_IPacket = IPacket;
276
- type packet_types_NodeType = NodeType;
277
- declare const packet_types_NodeType: typeof NodeType;
278
- type packet_types_PathPayload = PathPayload;
279
- type packet_types_Payload = Payload;
280
- type packet_types_PayloadType = PayloadType;
281
- declare const packet_types_PayloadType: typeof PayloadType;
282
- type packet_types_RawCustomPayload = RawCustomPayload;
283
- type packet_types_RequestPayload = RequestPayload;
284
- type packet_types_RequestType = RequestType;
285
- declare const packet_types_RequestType: typeof RequestType;
286
- type packet_types_ResponsePayload = ResponsePayload;
287
- type packet_types_RouteType = RouteType;
288
- declare const packet_types_RouteType: typeof RouteType;
289
- type packet_types_TextPayload = TextPayload;
290
- type packet_types_TextType = TextType;
291
- declare const packet_types_TextType: typeof TextType;
292
- type packet_types_TracePayload = TracePayload;
293
- type packet_types_Uint16 = Uint16;
294
- declare namespace packet_types {
295
- export { type packet_types_AckPayload as AckPayload, type packet_types_AdvertAppData as AdvertAppData, type packet_types_AdvertPayload as AdvertPayload, type packet_types_AnonReqPayload as AnonReqPayload, type packet_types_DecryptedAnonReq as DecryptedAnonReq, type packet_types_DecryptedGroupData as DecryptedGroupData, type packet_types_DecryptedGroupText as DecryptedGroupText, type packet_types_DecryptedRequest as DecryptedRequest, type packet_types_DecryptedResponse as DecryptedResponse, type packet_types_DecryptedText as DecryptedText, type packet_types_EncryptedPayload as EncryptedPayload, type packet_types_GroupDataPayload as GroupDataPayload, type packet_types_GroupTextPayload as GroupTextPayload, type packet_types_IPacket as IPacket, packet_types_NodeType as NodeType, type packet_types_PathPayload as PathPayload, type packet_types_Payload as Payload, packet_types_PayloadType as PayloadType, type packet_types_RawCustomPayload as RawCustomPayload, type packet_types_RequestPayload as RequestPayload, packet_types_RequestType as RequestType, type packet_types_ResponsePayload as ResponsePayload, packet_types_RouteType as RouteType, type packet_types_TextPayload as TextPayload, packet_types_TextType as TextType, type packet_types_TracePayload as TracePayload, type packet_types_Uint16 as Uint16 };
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
- declare class Packet implements IPacket {
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 };