@hamradio/meshcore 1.2.2 → 1.3.2
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.mjs → index.cjs} +339 -323
- package/dist/{index.d.mts → index.d.cts} +118 -132
- package/dist/index.d.ts +118 -132
- package/dist/index.js +296 -364
- package/package.json +12 -8
- package/dist/crypto.d.ts +0 -42
- package/dist/crypto.js +0 -199
- package/dist/crypto.types.d.ts +0 -26
- package/dist/crypto.types.js +0 -1
- package/dist/identity.d.ts +0 -65
- package/dist/identity.js +0 -302
- package/dist/identity.types.d.ts +0 -17
- package/dist/identity.types.js +0 -1
- package/dist/packet.d.ts +0 -32
- package/dist/packet.js +0 -242
- package/dist/packet.types.d.ts +0 -161
- package/dist/packet.types.js +0 -44
- package/dist/parser.d.ts +0 -31
- package/dist/parser.js +0 -124
package/dist/identity.types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { IPublicKey, ISharedSecret } from "./crypto.types";
|
|
2
|
-
export type NodeHash = number;
|
|
3
|
-
export interface IIdentity {
|
|
4
|
-
hash(): NodeHash;
|
|
5
|
-
toString(): string;
|
|
6
|
-
verify(signature: Uint8Array, message: Uint8Array): boolean;
|
|
7
|
-
matches(other: IIdentity | IPublicKey | Uint8Array | string): boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface ILocalIdentity extends IIdentity {
|
|
10
|
-
sign(message: Uint8Array): Uint8Array;
|
|
11
|
-
calculateSharedSecret(other: IIdentity | IPublicKey): ISharedSecret;
|
|
12
|
-
}
|
|
13
|
-
export interface IContact {
|
|
14
|
-
name: string;
|
|
15
|
-
identity: IIdentity;
|
|
16
|
-
calculateSharedSecret(me: ILocalIdentity): ISharedSecret;
|
|
17
|
-
}
|
package/dist/identity.types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/packet.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Payload, PayloadType, RouteType, type IPacket } from "./packet.types";
|
|
2
|
-
export declare class Packet implements IPacket {
|
|
3
|
-
header: number;
|
|
4
|
-
pathLength: number;
|
|
5
|
-
path: Uint8Array;
|
|
6
|
-
payload: Uint8Array;
|
|
7
|
-
transport?: [number, number];
|
|
8
|
-
routeType: RouteType;
|
|
9
|
-
payloadVersion: number;
|
|
10
|
-
payloadType: PayloadType;
|
|
11
|
-
pathHashCount: number;
|
|
12
|
-
pathHashSize: number;
|
|
13
|
-
pathHashBytes: number;
|
|
14
|
-
pathHashes: string[];
|
|
15
|
-
constructor(header: number, transport: [number, number] | undefined, pathLength: number, path: Uint8Array, payload: Uint8Array);
|
|
16
|
-
static fromBytes(bytes: Uint8Array | string): Packet;
|
|
17
|
-
static hasTransportCodes(routeType: RouteType): boolean;
|
|
18
|
-
hash(): string;
|
|
19
|
-
decode(): Payload;
|
|
20
|
-
private decodeEncryptedPayload;
|
|
21
|
-
private decodeRequest;
|
|
22
|
-
private decodeResponse;
|
|
23
|
-
private decodeText;
|
|
24
|
-
private decodeAck;
|
|
25
|
-
private decodeAdvert;
|
|
26
|
-
private decodeGroupText;
|
|
27
|
-
private decodeGroupData;
|
|
28
|
-
private decodeAnonReq;
|
|
29
|
-
private decodePath;
|
|
30
|
-
private decodeTrace;
|
|
31
|
-
private decodeRawCustom;
|
|
32
|
-
}
|
package/dist/packet.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
-
import { PayloadType, RouteType, } from "./packet.types";
|
|
3
|
-
import { base64ToBytes, BufferReader, bytesToHex } from "./parser";
|
|
4
|
-
export class Packet {
|
|
5
|
-
constructor(header, transport, pathLength, path, payload) {
|
|
6
|
-
this.header = header;
|
|
7
|
-
this.transport = transport;
|
|
8
|
-
this.pathLength = pathLength;
|
|
9
|
-
this.path = path;
|
|
10
|
-
this.payload = payload;
|
|
11
|
-
this.routeType = (header) & 0x03;
|
|
12
|
-
this.payloadVersion = (header >> 6) & 0x03;
|
|
13
|
-
this.payloadType = (header >> 2) & 0x0f;
|
|
14
|
-
this.pathHashSize = (pathLength >> 6) + 1;
|
|
15
|
-
this.pathHashCount = pathLength & 0x3f;
|
|
16
|
-
this.pathHashBytes = this.pathHashCount * this.pathHashSize;
|
|
17
|
-
this.pathHashes = [];
|
|
18
|
-
for (let i = 0; i < this.pathHashBytes; i += this.pathHashSize) {
|
|
19
|
-
const hashBytes = this.path.slice(i, i + this.pathHashSize);
|
|
20
|
-
const hashHex = bytesToHex(hashBytes);
|
|
21
|
-
this.pathHashes.push(hashHex);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
static fromBytes(bytes) {
|
|
25
|
-
if (typeof bytes === "string") {
|
|
26
|
-
bytes = base64ToBytes(bytes);
|
|
27
|
-
}
|
|
28
|
-
let offset = 0;
|
|
29
|
-
const header = bytes[offset++];
|
|
30
|
-
const routeType = header & 0x03;
|
|
31
|
-
let transport;
|
|
32
|
-
if (Packet.hasTransportCodes(routeType)) {
|
|
33
|
-
const uitn16View = new DataView(bytes.buffer, bytes.byteOffset + offset, 4);
|
|
34
|
-
transport = [uitn16View.getUint16(0, false), uitn16View.getUint16(2, false)];
|
|
35
|
-
offset += 4;
|
|
36
|
-
}
|
|
37
|
-
const pathLength = bytes[offset++];
|
|
38
|
-
const path = bytes.slice(offset, offset + pathLength);
|
|
39
|
-
offset += pathLength;
|
|
40
|
-
const payload = bytes.slice(offset);
|
|
41
|
-
return new Packet(header, transport, pathLength, path, payload);
|
|
42
|
-
}
|
|
43
|
-
static hasTransportCodes(routeType) {
|
|
44
|
-
return routeType === RouteType.TRANSPORT_FLOOD || routeType === RouteType.TRANSPORT_DIRECT;
|
|
45
|
-
}
|
|
46
|
-
hash() {
|
|
47
|
-
const hash = sha256.create();
|
|
48
|
-
hash.update(new Uint8Array([this.payloadType]));
|
|
49
|
-
if (this.payloadType === PayloadType.TRACE) {
|
|
50
|
-
hash.update(new Uint8Array([this.pathLength]));
|
|
51
|
-
}
|
|
52
|
-
hash.update(this.payload);
|
|
53
|
-
const digest = hash.digest();
|
|
54
|
-
return bytesToHex(digest.slice(0, 8));
|
|
55
|
-
}
|
|
56
|
-
decode() {
|
|
57
|
-
switch (this.payloadType) {
|
|
58
|
-
case PayloadType.REQUEST:
|
|
59
|
-
return this.decodeRequest();
|
|
60
|
-
case PayloadType.RESPONSE:
|
|
61
|
-
return this.decodeResponse();
|
|
62
|
-
case PayloadType.TEXT:
|
|
63
|
-
return this.decodeText();
|
|
64
|
-
case PayloadType.ACK:
|
|
65
|
-
return this.decodeAck();
|
|
66
|
-
case PayloadType.ADVERT:
|
|
67
|
-
return this.decodeAdvert();
|
|
68
|
-
case PayloadType.GROUP_TEXT:
|
|
69
|
-
return this.decodeGroupText();
|
|
70
|
-
case PayloadType.GROUP_DATA:
|
|
71
|
-
return this.decodeGroupData();
|
|
72
|
-
case PayloadType.ANON_REQ:
|
|
73
|
-
return this.decodeAnonReq();
|
|
74
|
-
case PayloadType.PATH:
|
|
75
|
-
return this.decodePath();
|
|
76
|
-
case PayloadType.TRACE:
|
|
77
|
-
return this.decodeTrace();
|
|
78
|
-
case PayloadType.RAW_CUSTOM:
|
|
79
|
-
return this.decodeRawCustom();
|
|
80
|
-
default:
|
|
81
|
-
throw new Error(`Unsupported payload type: ${this.payloadType}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
decodeEncryptedPayload(reader) {
|
|
85
|
-
const cipherMAC = reader.readBytes(2);
|
|
86
|
-
const cipherText = reader.readBytes(reader.remainingBytes());
|
|
87
|
-
return { cipherMAC, cipherText };
|
|
88
|
-
}
|
|
89
|
-
decodeRequest() {
|
|
90
|
-
if (this.payload.length < 4) {
|
|
91
|
-
throw new Error("Invalid request payload: too short");
|
|
92
|
-
}
|
|
93
|
-
const reader = new BufferReader(this.payload);
|
|
94
|
-
return {
|
|
95
|
-
type: PayloadType.REQUEST,
|
|
96
|
-
dst: reader.readByte(),
|
|
97
|
-
src: reader.readByte(),
|
|
98
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
decodeResponse() {
|
|
102
|
-
if (this.payload.length < 4) {
|
|
103
|
-
throw new Error("Invalid response payload: too short");
|
|
104
|
-
}
|
|
105
|
-
const reader = new BufferReader(this.payload);
|
|
106
|
-
return {
|
|
107
|
-
type: PayloadType.RESPONSE,
|
|
108
|
-
dst: reader.readByte(),
|
|
109
|
-
src: reader.readByte(),
|
|
110
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
decodeText() {
|
|
114
|
-
if (this.payload.length < 4) {
|
|
115
|
-
throw new Error("Invalid text payload: too short");
|
|
116
|
-
}
|
|
117
|
-
const reader = new BufferReader(this.payload);
|
|
118
|
-
return {
|
|
119
|
-
type: PayloadType.TEXT,
|
|
120
|
-
dst: reader.readByte(),
|
|
121
|
-
src: reader.readByte(),
|
|
122
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
decodeAck() {
|
|
126
|
-
if (this.payload.length < 4) {
|
|
127
|
-
throw new Error("Invalid ack payload: too short");
|
|
128
|
-
}
|
|
129
|
-
const reader = new BufferReader(this.payload);
|
|
130
|
-
return {
|
|
131
|
-
type: PayloadType.ACK,
|
|
132
|
-
checksum: reader.readBytes(4),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
decodeAdvert() {
|
|
136
|
-
if (this.payload.length < 4) {
|
|
137
|
-
throw new Error("Invalid advert payload: too short");
|
|
138
|
-
}
|
|
139
|
-
const reader = new BufferReader(this.payload);
|
|
140
|
-
const payload = {
|
|
141
|
-
type: PayloadType.ADVERT,
|
|
142
|
-
publicKey: reader.readBytes(32),
|
|
143
|
-
timestamp: reader.readTimestamp(),
|
|
144
|
-
signature: reader.readBytes(64),
|
|
145
|
-
};
|
|
146
|
-
const flags = reader.readByte();
|
|
147
|
-
const appdata = {
|
|
148
|
-
nodeType: flags & 0x0f,
|
|
149
|
-
hasLocation: (flags & 0x10) !== 0,
|
|
150
|
-
hasFeature1: (flags & 0x20) !== 0,
|
|
151
|
-
hasFeature2: (flags & 0x40) !== 0,
|
|
152
|
-
hasName: (flags & 0x80) !== 0,
|
|
153
|
-
};
|
|
154
|
-
if (appdata.hasLocation) {
|
|
155
|
-
const lat = reader.readInt32LE() / 100000;
|
|
156
|
-
const lon = reader.readInt32LE() / 100000;
|
|
157
|
-
appdata.location = [lat, lon];
|
|
158
|
-
}
|
|
159
|
-
if (appdata.hasFeature1) {
|
|
160
|
-
appdata.feature1 = reader.readUint16LE();
|
|
161
|
-
}
|
|
162
|
-
if (appdata.hasFeature2) {
|
|
163
|
-
appdata.feature2 = reader.readUint16LE();
|
|
164
|
-
}
|
|
165
|
-
if (appdata.hasName) {
|
|
166
|
-
const nameBytes = reader.readBytes();
|
|
167
|
-
let nullPos = nameBytes.indexOf(0);
|
|
168
|
-
if (nullPos === -1) {
|
|
169
|
-
nullPos = nameBytes.length;
|
|
170
|
-
}
|
|
171
|
-
appdata.name = new TextDecoder('utf-8').decode(nameBytes.subarray(0, nullPos));
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
...payload,
|
|
175
|
-
appdata
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
decodeGroupText() {
|
|
179
|
-
if (this.payload.length < 3) {
|
|
180
|
-
throw new Error("Invalid group text payload: too short");
|
|
181
|
-
}
|
|
182
|
-
const reader = new BufferReader(this.payload);
|
|
183
|
-
return {
|
|
184
|
-
type: PayloadType.GROUP_TEXT,
|
|
185
|
-
channelHash: reader.readByte(),
|
|
186
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
decodeGroupData() {
|
|
190
|
-
if (this.payload.length < 3) {
|
|
191
|
-
throw new Error("Invalid group data payload: too short");
|
|
192
|
-
}
|
|
193
|
-
const reader = new BufferReader(this.payload);
|
|
194
|
-
return {
|
|
195
|
-
type: PayloadType.GROUP_DATA,
|
|
196
|
-
channelHash: reader.readByte(),
|
|
197
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
decodeAnonReq() {
|
|
201
|
-
if (this.payload.length < 1 + 32 + 2) {
|
|
202
|
-
throw new Error("Invalid anon req payload: too short");
|
|
203
|
-
}
|
|
204
|
-
const reader = new BufferReader(this.payload);
|
|
205
|
-
return {
|
|
206
|
-
type: PayloadType.ANON_REQ,
|
|
207
|
-
dst: reader.readByte(),
|
|
208
|
-
publicKey: reader.readBytes(32),
|
|
209
|
-
encrypted: this.decodeEncryptedPayload(reader),
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
decodePath() {
|
|
213
|
-
if (this.payload.length < 2) {
|
|
214
|
-
throw new Error("Invalid path payload: too short");
|
|
215
|
-
}
|
|
216
|
-
const reader = new BufferReader(this.payload);
|
|
217
|
-
return {
|
|
218
|
-
type: PayloadType.PATH,
|
|
219
|
-
dst: reader.readByte(),
|
|
220
|
-
src: reader.readByte(),
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
decodeTrace() {
|
|
224
|
-
if (this.payload.length < 9) {
|
|
225
|
-
throw new Error("Invalid trace payload: too short");
|
|
226
|
-
}
|
|
227
|
-
const reader = new BufferReader(this.payload);
|
|
228
|
-
return {
|
|
229
|
-
type: PayloadType.TRACE,
|
|
230
|
-
tag: reader.readUint32LE() >>> 0,
|
|
231
|
-
authCode: reader.readUint32LE() >>> 0,
|
|
232
|
-
flags: reader.readByte() & 0x03,
|
|
233
|
-
nodes: reader.readBytes()
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
decodeRawCustom() {
|
|
237
|
-
return {
|
|
238
|
-
type: PayloadType.RAW_CUSTOM,
|
|
239
|
-
data: this.payload,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
}
|
package/dist/packet.types.d.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { NodeHash } from "./identity.types";
|
|
2
|
-
export type Uint16 = number;
|
|
3
|
-
export interface IPacket {
|
|
4
|
-
header: number;
|
|
5
|
-
transport?: [Uint16, Uint16];
|
|
6
|
-
pathLength: number;
|
|
7
|
-
path: Uint8Array;
|
|
8
|
-
payload: Uint8Array;
|
|
9
|
-
decode(): Payload;
|
|
10
|
-
}
|
|
11
|
-
export declare enum RouteType {
|
|
12
|
-
TRANSPORT_FLOOD = 0,
|
|
13
|
-
FLOOD = 1,
|
|
14
|
-
DIRECT = 2,
|
|
15
|
-
TRANSPORT_DIRECT = 3
|
|
16
|
-
}
|
|
17
|
-
export declare enum PayloadType {
|
|
18
|
-
REQUEST = 0,
|
|
19
|
-
RESPONSE = 1,
|
|
20
|
-
TEXT = 2,
|
|
21
|
-
ACK = 3,
|
|
22
|
-
ADVERT = 4,
|
|
23
|
-
GROUP_TEXT = 5,
|
|
24
|
-
GROUP_DATA = 6,
|
|
25
|
-
ANON_REQ = 7,
|
|
26
|
-
PATH = 8,
|
|
27
|
-
TRACE = 9,
|
|
28
|
-
RAW_CUSTOM = 15
|
|
29
|
-
}
|
|
30
|
-
export type Payload = RequestPayload | ResponsePayload | TextPayload | AckPayload | AdvertPayload | GroupTextPayload | GroupDataPayload | AnonReqPayload | PathPayload | TracePayload | RawCustomPayload;
|
|
31
|
-
export interface EncryptedPayload {
|
|
32
|
-
cipherMAC: Uint8Array;
|
|
33
|
-
cipherText: Uint8Array;
|
|
34
|
-
}
|
|
35
|
-
export interface RequestPayload {
|
|
36
|
-
type: PayloadType.REQUEST;
|
|
37
|
-
dst: NodeHash;
|
|
38
|
-
src: NodeHash;
|
|
39
|
-
encrypted: EncryptedPayload;
|
|
40
|
-
decrypted?: DecryptedRequest;
|
|
41
|
-
}
|
|
42
|
-
export declare enum RequestType {
|
|
43
|
-
GET_STATS = 1,
|
|
44
|
-
KEEP_ALIVE = 2,
|
|
45
|
-
GET_TELEMETRY = 3,
|
|
46
|
-
GET_MIN_MAX_AVG = 4,
|
|
47
|
-
GET_ACL = 5,
|
|
48
|
-
GET_NEIGHBORS = 6,
|
|
49
|
-
GET_OWNER_INFO = 7
|
|
50
|
-
}
|
|
51
|
-
export interface DecryptedRequest {
|
|
52
|
-
timestamp: Date;
|
|
53
|
-
requestType: RequestType;
|
|
54
|
-
requestData: Uint8Array;
|
|
55
|
-
}
|
|
56
|
-
export interface ResponsePayload {
|
|
57
|
-
type: PayloadType.RESPONSE;
|
|
58
|
-
dst: NodeHash;
|
|
59
|
-
src: NodeHash;
|
|
60
|
-
encrypted: EncryptedPayload;
|
|
61
|
-
decrypted?: DecryptedResponse;
|
|
62
|
-
}
|
|
63
|
-
export interface DecryptedResponse {
|
|
64
|
-
timestamp: Date;
|
|
65
|
-
responseData: Uint8Array;
|
|
66
|
-
}
|
|
67
|
-
export interface TextPayload {
|
|
68
|
-
type: PayloadType.TEXT;
|
|
69
|
-
dst: NodeHash;
|
|
70
|
-
src: NodeHash;
|
|
71
|
-
encrypted: EncryptedPayload;
|
|
72
|
-
decrypted?: DecryptedText;
|
|
73
|
-
}
|
|
74
|
-
export declare enum TextType {
|
|
75
|
-
PLAIN_TEXT = 0,
|
|
76
|
-
CLI_COMMAND = 1,
|
|
77
|
-
SIGNED_PLAIN_TEXT = 2
|
|
78
|
-
}
|
|
79
|
-
export interface DecryptedText {
|
|
80
|
-
timestamp: Date;
|
|
81
|
-
textType: TextType;
|
|
82
|
-
attempt: number;
|
|
83
|
-
message: string;
|
|
84
|
-
}
|
|
85
|
-
export interface AckPayload {
|
|
86
|
-
type: PayloadType.ACK;
|
|
87
|
-
checksum: Uint8Array;
|
|
88
|
-
}
|
|
89
|
-
export interface AdvertPayload {
|
|
90
|
-
type: PayloadType.ADVERT;
|
|
91
|
-
publicKey: Uint8Array;
|
|
92
|
-
timestamp: Date;
|
|
93
|
-
signature: Uint8Array;
|
|
94
|
-
appdata: AdvertAppData;
|
|
95
|
-
}
|
|
96
|
-
export declare enum NodeType {
|
|
97
|
-
CHAT_NODE = 1,
|
|
98
|
-
REPEATER = 2,
|
|
99
|
-
ROOM_SERVER = 3,
|
|
100
|
-
SENSOR_NODE = 4
|
|
101
|
-
}
|
|
102
|
-
export interface AdvertAppData {
|
|
103
|
-
nodeType: NodeType;
|
|
104
|
-
hasLocation: boolean;
|
|
105
|
-
location?: [number, number];
|
|
106
|
-
hasFeature1: boolean;
|
|
107
|
-
feature1?: Uint16;
|
|
108
|
-
hasFeature2: boolean;
|
|
109
|
-
feature2?: Uint16;
|
|
110
|
-
hasName: boolean;
|
|
111
|
-
name?: string;
|
|
112
|
-
}
|
|
113
|
-
export interface GroupTextPayload {
|
|
114
|
-
type: PayloadType.GROUP_TEXT;
|
|
115
|
-
channelHash: NodeHash;
|
|
116
|
-
encrypted: EncryptedPayload;
|
|
117
|
-
decrypted?: DecryptedGroupText;
|
|
118
|
-
}
|
|
119
|
-
export interface DecryptedGroupText {
|
|
120
|
-
timestamp: Date;
|
|
121
|
-
textType: TextType;
|
|
122
|
-
attempt: number;
|
|
123
|
-
message: string;
|
|
124
|
-
}
|
|
125
|
-
export interface GroupDataPayload {
|
|
126
|
-
type: PayloadType.GROUP_DATA;
|
|
127
|
-
channelHash: NodeHash;
|
|
128
|
-
encrypted: EncryptedPayload;
|
|
129
|
-
decrypted?: DecryptedGroupData;
|
|
130
|
-
}
|
|
131
|
-
export interface DecryptedGroupData {
|
|
132
|
-
timestamp: Date;
|
|
133
|
-
data: Uint8Array;
|
|
134
|
-
}
|
|
135
|
-
export interface AnonReqPayload {
|
|
136
|
-
type: PayloadType.ANON_REQ;
|
|
137
|
-
dst: NodeHash;
|
|
138
|
-
publicKey: Uint8Array;
|
|
139
|
-
encrypted: EncryptedPayload;
|
|
140
|
-
decrypted?: DecryptedAnonReq;
|
|
141
|
-
}
|
|
142
|
-
export interface DecryptedAnonReq {
|
|
143
|
-
timestamp: Date;
|
|
144
|
-
data: Uint8Array;
|
|
145
|
-
}
|
|
146
|
-
export interface PathPayload {
|
|
147
|
-
type: PayloadType.PATH;
|
|
148
|
-
dst: NodeHash;
|
|
149
|
-
src: NodeHash;
|
|
150
|
-
}
|
|
151
|
-
export interface TracePayload {
|
|
152
|
-
type: PayloadType.TRACE;
|
|
153
|
-
tag: number;
|
|
154
|
-
authCode: number;
|
|
155
|
-
flags: number;
|
|
156
|
-
nodes: Uint8Array;
|
|
157
|
-
}
|
|
158
|
-
export interface RawCustomPayload {
|
|
159
|
-
type: PayloadType.RAW_CUSTOM;
|
|
160
|
-
data: Uint8Array;
|
|
161
|
-
}
|
package/dist/packet.types.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export var RouteType;
|
|
2
|
-
(function (RouteType) {
|
|
3
|
-
RouteType[RouteType["TRANSPORT_FLOOD"] = 0] = "TRANSPORT_FLOOD";
|
|
4
|
-
RouteType[RouteType["FLOOD"] = 1] = "FLOOD";
|
|
5
|
-
RouteType[RouteType["DIRECT"] = 2] = "DIRECT";
|
|
6
|
-
RouteType[RouteType["TRANSPORT_DIRECT"] = 3] = "TRANSPORT_DIRECT";
|
|
7
|
-
})(RouteType || (RouteType = {}));
|
|
8
|
-
export var PayloadType;
|
|
9
|
-
(function (PayloadType) {
|
|
10
|
-
PayloadType[PayloadType["REQUEST"] = 0] = "REQUEST";
|
|
11
|
-
PayloadType[PayloadType["RESPONSE"] = 1] = "RESPONSE";
|
|
12
|
-
PayloadType[PayloadType["TEXT"] = 2] = "TEXT";
|
|
13
|
-
PayloadType[PayloadType["ACK"] = 3] = "ACK";
|
|
14
|
-
PayloadType[PayloadType["ADVERT"] = 4] = "ADVERT";
|
|
15
|
-
PayloadType[PayloadType["GROUP_TEXT"] = 5] = "GROUP_TEXT";
|
|
16
|
-
PayloadType[PayloadType["GROUP_DATA"] = 6] = "GROUP_DATA";
|
|
17
|
-
PayloadType[PayloadType["ANON_REQ"] = 7] = "ANON_REQ";
|
|
18
|
-
PayloadType[PayloadType["PATH"] = 8] = "PATH";
|
|
19
|
-
PayloadType[PayloadType["TRACE"] = 9] = "TRACE";
|
|
20
|
-
PayloadType[PayloadType["RAW_CUSTOM"] = 15] = "RAW_CUSTOM";
|
|
21
|
-
})(PayloadType || (PayloadType = {}));
|
|
22
|
-
export var RequestType;
|
|
23
|
-
(function (RequestType) {
|
|
24
|
-
RequestType[RequestType["GET_STATS"] = 1] = "GET_STATS";
|
|
25
|
-
RequestType[RequestType["KEEP_ALIVE"] = 2] = "KEEP_ALIVE";
|
|
26
|
-
RequestType[RequestType["GET_TELEMETRY"] = 3] = "GET_TELEMETRY";
|
|
27
|
-
RequestType[RequestType["GET_MIN_MAX_AVG"] = 4] = "GET_MIN_MAX_AVG";
|
|
28
|
-
RequestType[RequestType["GET_ACL"] = 5] = "GET_ACL";
|
|
29
|
-
RequestType[RequestType["GET_NEIGHBORS"] = 6] = "GET_NEIGHBORS";
|
|
30
|
-
RequestType[RequestType["GET_OWNER_INFO"] = 7] = "GET_OWNER_INFO";
|
|
31
|
-
})(RequestType || (RequestType = {}));
|
|
32
|
-
export var TextType;
|
|
33
|
-
(function (TextType) {
|
|
34
|
-
TextType[TextType["PLAIN_TEXT"] = 0] = "PLAIN_TEXT";
|
|
35
|
-
TextType[TextType["CLI_COMMAND"] = 1] = "CLI_COMMAND";
|
|
36
|
-
TextType[TextType["SIGNED_PLAIN_TEXT"] = 2] = "SIGNED_PLAIN_TEXT";
|
|
37
|
-
})(TextType || (TextType = {}));
|
|
38
|
-
export var NodeType;
|
|
39
|
-
(function (NodeType) {
|
|
40
|
-
NodeType[NodeType["CHAT_NODE"] = 1] = "CHAT_NODE";
|
|
41
|
-
NodeType[NodeType["REPEATER"] = 2] = "REPEATER";
|
|
42
|
-
NodeType[NodeType["ROOM_SERVER"] = 3] = "ROOM_SERVER";
|
|
43
|
-
NodeType[NodeType["SENSOR_NODE"] = 4] = "SENSOR_NODE";
|
|
44
|
-
})(NodeType || (NodeType = {}));
|
package/dist/parser.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { equalBytes } from "@noble/ciphers/utils.js";
|
|
2
|
-
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
3
|
-
export { bytesToHex, equalBytes };
|
|
4
|
-
export declare const base64ToBytes: (base64: string, size?: number) => Uint8Array;
|
|
5
|
-
export declare const hexToBytes: (hex: string, size?: number) => Uint8Array;
|
|
6
|
-
export declare class BufferReader {
|
|
7
|
-
private buffer;
|
|
8
|
-
private offset;
|
|
9
|
-
constructor(buffer: Uint8Array);
|
|
10
|
-
readByte(): number;
|
|
11
|
-
readBytes(length?: number): Uint8Array;
|
|
12
|
-
hasMore(): boolean;
|
|
13
|
-
remainingBytes(): number;
|
|
14
|
-
peekByte(): number;
|
|
15
|
-
readUint16LE(): number;
|
|
16
|
-
readUint32LE(): number;
|
|
17
|
-
readInt16LE(): number;
|
|
18
|
-
readInt32LE(): number;
|
|
19
|
-
readTimestamp(): Date;
|
|
20
|
-
}
|
|
21
|
-
export declare class BufferWriter {
|
|
22
|
-
private buffer;
|
|
23
|
-
writeByte(value: number): void;
|
|
24
|
-
writeBytes(bytes: Uint8Array): void;
|
|
25
|
-
writeUint16LE(value: number): void;
|
|
26
|
-
writeUint32LE(value: number): void;
|
|
27
|
-
writeInt16LE(value: number): void;
|
|
28
|
-
writeInt32LE(value: number): void;
|
|
29
|
-
writeTimestamp(date: Date): void;
|
|
30
|
-
toBytes(): Uint8Array;
|
|
31
|
-
}
|
package/dist/parser.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { equalBytes } from "@noble/ciphers/utils.js";
|
|
2
|
-
import { bytesToHex, hexToBytes as nobleHexToBytes } from "@noble/hashes/utils.js";
|
|
3
|
-
export { bytesToHex, equalBytes };
|
|
4
|
-
export const base64ToBytes = (base64, size) => {
|
|
5
|
-
// Normalize URL-safe base64 to standard base64
|
|
6
|
-
let normalized = base64.replace(/-/g, '+').replace(/_/g, '/');
|
|
7
|
-
// Add padding if missing
|
|
8
|
-
while (normalized.length % 4 !== 0) {
|
|
9
|
-
normalized += '=';
|
|
10
|
-
}
|
|
11
|
-
const binaryString = atob(normalized);
|
|
12
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
13
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
14
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
15
|
-
}
|
|
16
|
-
if (size !== undefined && bytes.length !== size) {
|
|
17
|
-
throw new Error(`Invalid base64 length: expected ${size} bytes, got ${bytes.length}`);
|
|
18
|
-
}
|
|
19
|
-
return bytes;
|
|
20
|
-
};
|
|
21
|
-
// Note: encodedStringToBytes removed — prefer explicit parsers.
|
|
22
|
-
// Use `hexToBytes` for hex inputs and `base64ToBytes` for base64 inputs.
|
|
23
|
-
// Wrapper around @noble/hashes hexToBytes that optionally validates size.
|
|
24
|
-
export const hexToBytes = (hex, size) => {
|
|
25
|
-
const bytes = nobleHexToBytes(hex);
|
|
26
|
-
if (size !== undefined && bytes.length !== size) {
|
|
27
|
-
throw new Error(`Invalid hex length: expected ${size} bytes, got ${bytes.length}`);
|
|
28
|
-
}
|
|
29
|
-
return bytes;
|
|
30
|
-
};
|
|
31
|
-
export class BufferReader {
|
|
32
|
-
constructor(buffer) {
|
|
33
|
-
this.buffer = buffer;
|
|
34
|
-
this.offset = 0;
|
|
35
|
-
}
|
|
36
|
-
readByte() {
|
|
37
|
-
if (!this.hasMore())
|
|
38
|
-
throw new Error('read past end');
|
|
39
|
-
return this.buffer[this.offset++];
|
|
40
|
-
}
|
|
41
|
-
readBytes(length) {
|
|
42
|
-
if (length === undefined) {
|
|
43
|
-
length = this.buffer.length - this.offset;
|
|
44
|
-
}
|
|
45
|
-
if (this.remainingBytes() < length)
|
|
46
|
-
throw new Error('read past end');
|
|
47
|
-
const bytes = this.buffer.slice(this.offset, this.offset + length);
|
|
48
|
-
this.offset += length;
|
|
49
|
-
return bytes;
|
|
50
|
-
}
|
|
51
|
-
hasMore() {
|
|
52
|
-
return this.offset < this.buffer.length;
|
|
53
|
-
}
|
|
54
|
-
remainingBytes() {
|
|
55
|
-
return this.buffer.length - this.offset;
|
|
56
|
-
}
|
|
57
|
-
peekByte() {
|
|
58
|
-
if (!this.hasMore())
|
|
59
|
-
throw new Error('read past end');
|
|
60
|
-
return this.buffer[this.offset];
|
|
61
|
-
}
|
|
62
|
-
readUint16LE() {
|
|
63
|
-
if (this.remainingBytes() < 2)
|
|
64
|
-
throw new Error('read past end');
|
|
65
|
-
const value = this.buffer[this.offset] | (this.buffer[this.offset + 1] << 8);
|
|
66
|
-
this.offset += 2;
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
readUint32LE() {
|
|
70
|
-
if (this.remainingBytes() < 4)
|
|
71
|
-
throw new Error('read past end');
|
|
72
|
-
const value = (this.buffer[this.offset] | (this.buffer[this.offset + 1] << 8) | (this.buffer[this.offset + 2] << 16) | (this.buffer[this.offset + 3] << 24)) >>> 0;
|
|
73
|
-
this.offset += 4;
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
readInt16LE() {
|
|
77
|
-
if (this.remainingBytes() < 2)
|
|
78
|
-
throw new Error('read past end');
|
|
79
|
-
const value = this.buffer[this.offset] | (this.buffer[this.offset + 1] << 8);
|
|
80
|
-
this.offset += 2;
|
|
81
|
-
return value < 0x8000 ? value : value - 0x10000;
|
|
82
|
-
}
|
|
83
|
-
readInt32LE() {
|
|
84
|
-
if (this.remainingBytes() < 4)
|
|
85
|
-
throw new Error('read past end');
|
|
86
|
-
const u = (this.buffer[this.offset] | (this.buffer[this.offset + 1] << 8) | (this.buffer[this.offset + 2] << 16) | (this.buffer[this.offset + 3] << 24)) >>> 0;
|
|
87
|
-
this.offset += 4;
|
|
88
|
-
return u < 0x80000000 ? u : u - 0x100000000;
|
|
89
|
-
}
|
|
90
|
-
readTimestamp() {
|
|
91
|
-
const timestamp = this.readUint32LE();
|
|
92
|
-
return new Date(timestamp * 1000);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
export class BufferWriter {
|
|
96
|
-
constructor() {
|
|
97
|
-
this.buffer = [];
|
|
98
|
-
}
|
|
99
|
-
writeByte(value) {
|
|
100
|
-
this.buffer.push(value & 0xFF);
|
|
101
|
-
}
|
|
102
|
-
writeBytes(bytes) {
|
|
103
|
-
this.buffer.push(...bytes);
|
|
104
|
-
}
|
|
105
|
-
writeUint16LE(value) {
|
|
106
|
-
this.buffer.push(value & 0xFF, (value >> 8) & 0xFF);
|
|
107
|
-
}
|
|
108
|
-
writeUint32LE(value) {
|
|
109
|
-
this.buffer.push(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF, (value >> 24) & 0xFF);
|
|
110
|
-
}
|
|
111
|
-
writeInt16LE(value) {
|
|
112
|
-
this.writeUint16LE(value < 0 ? value + 0x10000 : value);
|
|
113
|
-
}
|
|
114
|
-
writeInt32LE(value) {
|
|
115
|
-
this.writeUint32LE(value < 0 ? value + 0x100000000 : value);
|
|
116
|
-
}
|
|
117
|
-
writeTimestamp(date) {
|
|
118
|
-
const timestamp = Math.floor(date.getTime() / 1000);
|
|
119
|
-
this.writeUint32LE(timestamp);
|
|
120
|
-
}
|
|
121
|
-
toBytes() {
|
|
122
|
-
return new Uint8Array(this.buffer);
|
|
123
|
-
}
|
|
124
|
-
}
|