@hamradio/meshcore 1.1.1

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.
@@ -0,0 +1,392 @@
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
+ interface IPublicKey {
27
+ toHash(): NodeHash;
28
+ toBytes(): Uint8Array;
29
+ toString(): string;
30
+ equals(other: IPublicKey | Uint8Array | string): boolean;
31
+ verify(message: Uint8Array, signature: Uint8Array): boolean;
32
+ }
33
+ interface IPrivateKey extends IPublicKey {
34
+ toPublicKey(): IPublicKey;
35
+ sign(message: Uint8Array): Uint8Array;
36
+ }
37
+ interface ISharedSecret {
38
+ toHash(): NodeHash;
39
+ toBytes(): Uint8Array;
40
+ toString(): string;
41
+ decrypt(hmac: Uint8Array, ciphertext: Uint8Array): Uint8Array;
42
+ encrypt(data: Uint8Array): {
43
+ hmac: Uint8Array;
44
+ ciphertext: Uint8Array;
45
+ };
46
+ }
47
+ interface IStaticSecret {
48
+ publicKey(): IPublicKey;
49
+ diffieHellman(otherPublicKey: IPublicKey): ISharedSecret;
50
+ }
51
+
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;
65
+ toString(): string;
66
+ equals(other: PublicKey | Uint8Array | string): boolean;
67
+ verify(message: Uint8Array, signature: Uint8Array): boolean;
68
+ }
69
+ declare class PrivateKey {
70
+ private secretKey;
71
+ private publicKey;
72
+ constructor(seed: Uint8Array | string);
73
+ toPublicKey(): PublicKey;
74
+ toBytes(): Uint8Array;
75
+ toString(): string;
76
+ sign(message: Uint8Array): Uint8Array;
77
+ calculateSharedSecret(other: PublicKey | Uint8Array | string): Uint8Array;
78
+ static generate(): PrivateKey;
79
+ }
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;
93
+ }
94
+ declare class StaticSecret implements IStaticSecret {
95
+ private secret;
96
+ constructor(secret: Uint8Array | string);
97
+ publicKey(): IPublicKey;
98
+ diffieHellman(otherPublicKey: IPublicKey): SharedSecret;
99
+ }
100
+
101
+ type Uint16 = number;
102
+ interface IPacket {
103
+ header: number;
104
+ transport?: [Uint16, Uint16];
105
+ pathLength: number;
106
+ path: Uint8Array;
107
+ payload: Uint8Array;
108
+ decode(): Payload;
109
+ }
110
+ declare enum RouteType {
111
+ TRANSPORT_FLOOD = 0,
112
+ FLOOD = 1,
113
+ DIRECT = 2,
114
+ TRANSPORT_DIRECT = 3
115
+ }
116
+ declare enum PayloadType {
117
+ REQUEST = 0,
118
+ RESPONSE = 1,
119
+ TEXT = 2,
120
+ ACK = 3,
121
+ ADVERT = 4,
122
+ GROUP_TEXT = 5,
123
+ GROUP_DATA = 6,
124
+ ANON_REQ = 7,
125
+ PATH = 8,
126
+ TRACE = 9,
127
+ RAW_CUSTOM = 15
128
+ }
129
+ type Payload = RequestPayload | ResponsePayload | TextPayload | AckPayload | AdvertPayload | GroupTextPayload | GroupDataPayload | AnonReqPayload | PathPayload | TracePayload | RawCustomPayload;
130
+ interface EncryptedPayload {
131
+ cipherMAC: Uint8Array;
132
+ cipherText: Uint8Array;
133
+ }
134
+ interface RequestPayload {
135
+ type: PayloadType.REQUEST;
136
+ dst: NodeHash;
137
+ src: NodeHash;
138
+ encrypted: EncryptedPayload;
139
+ decrypted?: DecryptedRequest;
140
+ }
141
+ declare enum RequestType {
142
+ GET_STATS = 1,
143
+ KEEP_ALIVE = 2,
144
+ GET_TELEMETRY = 3,
145
+ GET_MIN_MAX_AVG = 4,
146
+ GET_ACL = 5,
147
+ GET_NEIGHBORS = 6,
148
+ GET_OWNER_INFO = 7
149
+ }
150
+ interface DecryptedRequest {
151
+ timestamp: Date;
152
+ requestType: RequestType;
153
+ requestData: Uint8Array;
154
+ }
155
+ interface ResponsePayload {
156
+ type: PayloadType.RESPONSE;
157
+ dst: NodeHash;
158
+ src: NodeHash;
159
+ encrypted: EncryptedPayload;
160
+ decrypted?: DecryptedResponse;
161
+ }
162
+ interface DecryptedResponse {
163
+ timestamp: Date;
164
+ responseData: Uint8Array;
165
+ }
166
+ interface TextPayload {
167
+ type: PayloadType.TEXT;
168
+ dst: NodeHash;
169
+ src: NodeHash;
170
+ encrypted: EncryptedPayload;
171
+ decrypted?: DecryptedText;
172
+ }
173
+ declare enum TextType {
174
+ PLAIN_TEXT = 0,
175
+ CLI_COMMAND = 1,
176
+ SIGNED_PLAIN_TEXT = 2
177
+ }
178
+ interface DecryptedText {
179
+ timestamp: Date;
180
+ textType: TextType;
181
+ attempt: number;
182
+ message: string;
183
+ }
184
+ interface AckPayload {
185
+ type: PayloadType.ACK;
186
+ checksum: Uint8Array;
187
+ }
188
+ interface AdvertPayload {
189
+ type: PayloadType.ADVERT;
190
+ publicKey: Uint8Array;
191
+ timestamp: Date;
192
+ signature: Uint8Array;
193
+ appdata: AdvertAppData;
194
+ }
195
+ declare enum NodeType {
196
+ CHAT_NODE = 1,
197
+ REPEATER = 2,
198
+ ROOM_SERVER = 3,
199
+ SENSOR_NODE = 4
200
+ }
201
+ interface AdvertAppData {
202
+ nodeType: NodeType;
203
+ hasLocation: boolean;
204
+ location?: [number, number];
205
+ hasFeature1: boolean;
206
+ feature1?: Uint16;
207
+ hasFeature2: boolean;
208
+ feature2?: Uint16;
209
+ hasName: boolean;
210
+ name?: string;
211
+ }
212
+ interface GroupTextPayload {
213
+ type: PayloadType.GROUP_TEXT;
214
+ channelHash: NodeHash;
215
+ encrypted: EncryptedPayload;
216
+ decrypted?: DecryptedGroupText;
217
+ }
218
+ interface DecryptedGroupText {
219
+ timestamp: Date;
220
+ textType: TextType;
221
+ attempt: number;
222
+ message: string;
223
+ }
224
+ interface GroupDataPayload {
225
+ type: PayloadType.GROUP_DATA;
226
+ channelHash: NodeHash;
227
+ encrypted: EncryptedPayload;
228
+ decrypted?: DecryptedGroupData;
229
+ }
230
+ interface DecryptedGroupData {
231
+ timestamp: Date;
232
+ data: Uint8Array;
233
+ }
234
+ interface AnonReqPayload {
235
+ type: PayloadType.ANON_REQ;
236
+ dst: NodeHash;
237
+ publicKey: Uint8Array;
238
+ encrypted: EncryptedPayload;
239
+ decrypted?: DecryptedAnonReq;
240
+ }
241
+ interface DecryptedAnonReq {
242
+ timestamp: Date;
243
+ data: Uint8Array;
244
+ }
245
+ interface PathPayload {
246
+ type: PayloadType.PATH;
247
+ dst: NodeHash;
248
+ src: NodeHash;
249
+ }
250
+ interface TracePayload {
251
+ type: PayloadType.TRACE;
252
+ tag: number;
253
+ authCode: number;
254
+ flags: number;
255
+ nodes: Uint8Array;
256
+ }
257
+ interface RawCustomPayload {
258
+ type: PayloadType.RAW_CUSTOM;
259
+ data: Uint8Array;
260
+ }
261
+
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 };
296
+ }
297
+
298
+ declare const parseNodeHash: (hash: NodeHash | string | Uint8Array) => NodeHash;
299
+ declare class Identity implements IIdentity {
300
+ publicKey: PublicKey;
301
+ constructor(publicKey: PublicKey | Uint8Array | string);
302
+ hash(): NodeHash;
303
+ toString(): string;
304
+ verify(signature: Uint8Array, message: Uint8Array): boolean;
305
+ matches(other: Identity | PublicKey | Uint8Array | string): boolean;
306
+ }
307
+ declare class LocalIdentity extends Identity implements ILocalIdentity {
308
+ private privateKey;
309
+ constructor(privateKey: PrivateKey | Uint8Array | string, publicKey: PublicKey | Uint8Array | string);
310
+ sign(message: Uint8Array): Uint8Array;
311
+ calculateSharedSecret(other: IIdentity | IPublicKey): SharedSecret;
312
+ }
313
+ declare class Contact {
314
+ name: string;
315
+ identity: Identity;
316
+ constructor(name: string, identity: Identity | PublicKey | Uint8Array | string);
317
+ matches(hash: Uint8Array | PublicKey): boolean;
318
+ publicKey(): PublicKey;
319
+ calculateSharedSecret(me: LocalIdentity): SharedSecret;
320
+ }
321
+ declare class Group {
322
+ name: string;
323
+ private secret;
324
+ constructor(name: string, secret?: SharedSecret);
325
+ hash(): NodeHash;
326
+ decryptText(hmac: Uint8Array, ciphertext: Uint8Array): DecryptedGroupText;
327
+ encryptText(plain: DecryptedGroupText): {
328
+ hmac: Uint8Array;
329
+ ciphertext: Uint8Array;
330
+ };
331
+ decryptData(hmac: Uint8Array, ciphertext: Uint8Array): DecryptedGroupData;
332
+ encryptData(plain: DecryptedGroupData): {
333
+ hmac: Uint8Array;
334
+ ciphertext: Uint8Array;
335
+ };
336
+ }
337
+ declare class Contacts {
338
+ private localIdentities;
339
+ private contacts;
340
+ private groups;
341
+ addLocalIdentity(identity: LocalIdentity): void;
342
+ addContact(contact: Contact): void;
343
+ decrypt(src: NodeHash | PublicKey, dst: NodeHash, hmac: Uint8Array, ciphertext: Uint8Array): {
344
+ localIdentity: LocalIdentity;
345
+ contact: Contact;
346
+ decrypted: Uint8Array;
347
+ };
348
+ private calculateSharedSecret;
349
+ addGroup(group: Group): void;
350
+ decryptGroupText(channelHash: NodeHash, hmac: Uint8Array, ciphertext: Uint8Array): {
351
+ decrypted: DecryptedGroupText;
352
+ group: Group;
353
+ };
354
+ decryptGroupData(channelHash: NodeHash, hmac: Uint8Array, ciphertext: Uint8Array): {
355
+ decrypted: DecryptedGroupData;
356
+ group: Group;
357
+ };
358
+ }
359
+
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 };