@basmilius/apple-companion-link 0.0.3 → 0.0.5
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.js +3 -3
- package/dist/index.js.map +5 -5
- package/dist/test.d.ts +1 -0
- package/dist/test.js +5 -0
- package/dist/test.js.map +25 -0
- package/package.json +1 -2
- package/src/cli.ts +0 -19
- package/src/const.ts +0 -7
- package/src/crypto/chacha20.ts +0 -95
- package/src/crypto/curve25519.ts +0 -21
- package/src/crypto/hkdf.ts +0 -13
- package/src/crypto/index.ts +0 -13
- package/src/discovery/discovery.ts +0 -52
- package/src/discovery/index.ts +0 -1
- package/src/encoding/index.ts +0 -22
- package/src/encoding/opack.ts +0 -293
- package/src/encoding/plist.ts +0 -2
- package/src/encoding/tlv8.ts +0 -111
- package/src/index.ts +0 -3
- package/src/net/getLocalIP.ts +0 -25
- package/src/net/getMacAddress.ts +0 -25
- package/src/net/index.ts +0 -2
- package/src/protocol/api/companionLink.ts +0 -353
- package/src/protocol/companionLink.ts +0 -41
- package/src/protocol/index.ts +0 -1
- package/src/protocol/pairing/companionLink.ts +0 -286
- package/src/protocol/verify/companionLink.ts +0 -185
- package/src/socket/base.ts +0 -21
- package/src/socket/companionLink.ts +0 -255
- package/src/socket/index.ts +0 -2
- package/src/test.ts +0 -112
- package/src/transient.ts +0 -64
- package/src/types.d.ts +0 -40
package/src/encoding/opack.ts
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
type Packed = Uint8Array;
|
|
2
|
-
type ObjectList = Packed[];
|
|
3
|
-
|
|
4
|
-
class SizedInt extends Number {
|
|
5
|
-
size: number;
|
|
6
|
-
|
|
7
|
-
constructor(value: number, size: number) {
|
|
8
|
-
super(value);
|
|
9
|
-
this.size = size;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const _SIZED_INT_TYPES: Record<number, typeof SizedInt> = {};
|
|
14
|
-
|
|
15
|
-
export function sizedInt(value: number, size: number): SizedInt {
|
|
16
|
-
return new SizedInt(value, size);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
class OPACKFloat {
|
|
20
|
-
value: number;
|
|
21
|
-
|
|
22
|
-
constructor(value: number) {
|
|
23
|
-
this.value = value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function float(value: number) {
|
|
28
|
-
return new OPACKFloat(value);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
class OPACKInt {
|
|
32
|
-
value: number;
|
|
33
|
-
|
|
34
|
-
constructor(value: number) {
|
|
35
|
-
this.value = value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function int(value: number) {
|
|
40
|
-
return new OPACKInt(value);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function concat(arr: Uint8Array[]): Uint8Array {
|
|
44
|
-
const total = arr.reduce((s, a) => s + a.length, 0);
|
|
45
|
-
const out = new Uint8Array(total);
|
|
46
|
-
let off = 0;
|
|
47
|
-
for (const a of arr) {
|
|
48
|
-
out.set(a, off);
|
|
49
|
-
off += a.length;
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function u8(b: number) {
|
|
55
|
-
return Uint8Array.of(b);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function uintToLEBytes(value: number | bigint, byteLen: number): Uint8Array {
|
|
59
|
-
const out = new Uint8Array(byteLen);
|
|
60
|
-
let v = BigInt(value);
|
|
61
|
-
for (let i = 0; i < byteLen; i++) {
|
|
62
|
-
out[i] = Number(v & 0xffn);
|
|
63
|
-
v >>= 8n;
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {
|
|
69
|
-
const total = arrays.reduce((sum, a) => sum + a.length, 0);
|
|
70
|
-
const out = new Uint8Array(total);
|
|
71
|
-
let offset = 0;
|
|
72
|
-
for (const a of arrays) {
|
|
73
|
-
out.set(a, offset);
|
|
74
|
-
offset += a.length;
|
|
75
|
-
}
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function pack(data: any): Uint8Array {
|
|
80
|
-
return _pack(data, []);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function _pack(data: any, objectList: ObjectList): Uint8Array {
|
|
84
|
-
let packed: Uint8Array | null = null;
|
|
85
|
-
|
|
86
|
-
if (data === null || data === undefined) packed = u8(0x04);
|
|
87
|
-
else if (typeof data === 'boolean') packed = u8(data ? 0x01 : 0x02);
|
|
88
|
-
else if (data instanceof OPACKFloat) {
|
|
89
|
-
const buf = new ArrayBuffer(8);
|
|
90
|
-
new DataView(buf).setFloat64(0, data.value, true);
|
|
91
|
-
packed = concat([u8(0x36), new Uint8Array(buf)]);
|
|
92
|
-
} else if (data instanceof OPACKInt) {
|
|
93
|
-
const val = data.value;
|
|
94
|
-
if (val < 0x28) packed = u8(0x08 + val);
|
|
95
|
-
else if (val <= 0xff) packed = concatUint8Arrays([u8(0x30), uintToLEBytes(val, 1)]);
|
|
96
|
-
else if (val <= 0xffff) packed = concatUint8Arrays([u8(0x31), uintToLEBytes(val, 2)]);
|
|
97
|
-
else if (val <= 0xffffffff) packed = concatUint8Arrays([u8(0x32), uintToLEBytes(val, 4)]);
|
|
98
|
-
else packed = concatUint8Arrays([u8(0x33), uintToLEBytes(val, 8)]);
|
|
99
|
-
} else if (typeof data === 'number') {
|
|
100
|
-
if (!Number.isInteger(data)) {
|
|
101
|
-
const buf = new ArrayBuffer(8);
|
|
102
|
-
new DataView(buf).setFloat64(0, data, true);
|
|
103
|
-
packed = concat([u8(0x36), new Uint8Array(buf)]);
|
|
104
|
-
} else {
|
|
105
|
-
if (data < 0x28) packed = u8(0x08 + data);
|
|
106
|
-
else if (data <= 0xff) packed = concat([u8(0x30), uintToLEBytes(data, 1)]);
|
|
107
|
-
else if (data <= 0xffff) packed = concat([u8(0x31), uintToLEBytes(data, 2)]);
|
|
108
|
-
else if (data <= 0xffffffff) packed = concat([u8(0x32), uintToLEBytes(data, 4)]);
|
|
109
|
-
else packed = concat([u8(0x33), uintToLEBytes(data, 8)]);
|
|
110
|
-
}
|
|
111
|
-
} else if (data instanceof SizedInt) {
|
|
112
|
-
packed = concat([u8(0x30 + Math.log2(data.size)), uintToLEBytes(data.valueOf(), data.size)]);
|
|
113
|
-
} else if (typeof data === 'string') {
|
|
114
|
-
const b = new TextEncoder().encode(data);
|
|
115
|
-
const len = b.length;
|
|
116
|
-
if (len <= 0x20) packed = concat([u8(0x40 + len), b]);
|
|
117
|
-
else if (len <= 0xff) packed = concat([u8(0x61), uintToLEBytes(len, 1), b]);
|
|
118
|
-
else if (len <= 0xffff) packed = concat([u8(0x62), uintToLEBytes(len, 2), b]);
|
|
119
|
-
else if (len <= 0xffffff) packed = concat([u8(0x63), uintToLEBytes(len, 3), b]);
|
|
120
|
-
else packed = concat([u8(0x64), uintToLEBytes(len, 4), b]);
|
|
121
|
-
} else if (data instanceof Uint8Array || Buffer.isBuffer(data)) {
|
|
122
|
-
const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
123
|
-
const len = bytes.length;
|
|
124
|
-
if (len <= 0x20) packed = concat([u8(0x70 + len), bytes]);
|
|
125
|
-
else if (len <= 0xff) packed = concat([u8(0x91), uintToLEBytes(len, 1), bytes]);
|
|
126
|
-
else if (len <= 0xffff) packed = concat([u8(0x92), uintToLEBytes(len, 2), bytes]);
|
|
127
|
-
else packed = concat([u8(0x93), uintToLEBytes(len, 4), bytes]);
|
|
128
|
-
} else if (Array.isArray(data)) {
|
|
129
|
-
const body = concat(data.map(d => _pack(d, objectList)));
|
|
130
|
-
const len = data.length;
|
|
131
|
-
if (len <= 0x0f) {
|
|
132
|
-
packed = concat([u8(0xd0 + len), body]);
|
|
133
|
-
if (len >= 0x0f) packed = concat([packed, u8(0x03)]);
|
|
134
|
-
} else packed = concat([u8(0xdf), body, u8(0x03)]);
|
|
135
|
-
} else if (typeof data === 'object') {
|
|
136
|
-
const keys = Object.keys(data);
|
|
137
|
-
const len = keys.length;
|
|
138
|
-
const pairs: Uint8Array[] = [];
|
|
139
|
-
for (const k of keys) {
|
|
140
|
-
pairs.push(_pack(k, objectList));
|
|
141
|
-
pairs.push(_pack((data as any)[k], objectList));
|
|
142
|
-
}
|
|
143
|
-
let header: Uint8Array;
|
|
144
|
-
if (len <= 0x0f) {
|
|
145
|
-
header = u8(0xE0 + len);
|
|
146
|
-
} else {
|
|
147
|
-
header = u8(0xEF);
|
|
148
|
-
}
|
|
149
|
-
packed = concatUint8Arrays([header, concatUint8Arrays(pairs)]);
|
|
150
|
-
// terminator
|
|
151
|
-
if (len >= 0x0f || objectList.some(v => v === packed)) {
|
|
152
|
-
packed = concatUint8Arrays([packed, u8(0x81)]);
|
|
153
|
-
}
|
|
154
|
-
} else throw new TypeError(typeof data + '');
|
|
155
|
-
|
|
156
|
-
// Object reuse
|
|
157
|
-
const idx = objectList.findIndex(v => v.length === packed!.length && v.every((x, i) => x === packed![i]));
|
|
158
|
-
if (idx >= 0) {
|
|
159
|
-
if (idx < 0x21) packed = u8(0xA0 + idx);
|
|
160
|
-
else if (idx <= 0xff) packed = concat([u8(0xC1), uintToLEBytes(idx, 1)]);
|
|
161
|
-
else if (idx <= 0xffff) packed = concat([u8(0xC2), uintToLEBytes(idx, 2)]);
|
|
162
|
-
else if (idx <= 0xffffffff) packed = concat([u8(0xC3), uintToLEBytes(idx, 4)]);
|
|
163
|
-
else packed = concat([u8(0xC4), uintToLEBytes(idx, 8)]);
|
|
164
|
-
} else if (packed!.length > 1) objectList.push(packed!);
|
|
165
|
-
|
|
166
|
-
return packed!;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/* UNPACK */
|
|
170
|
-
export function unpack(data: Uint8Array): [any, Uint8Array] {
|
|
171
|
-
return _unpack(data, []);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function _unpack(data: Uint8Array, objectList: ObjectList): [any, Uint8Array] {
|
|
175
|
-
if (data.length === 0) throw new TypeError('No data to unpack');
|
|
176
|
-
let addToObjectList = true;
|
|
177
|
-
const tag = data[0];
|
|
178
|
-
|
|
179
|
-
// simple tokens
|
|
180
|
-
if (tag === 0x01) return [true, data.subarray(1)];
|
|
181
|
-
if (tag === 0x02) return [false, data.subarray(1)];
|
|
182
|
-
if (tag === 0x04) return [null, data.subarray(1)];
|
|
183
|
-
if (tag === 0x05) {
|
|
184
|
-
const uuidBytes = data.subarray(1, 17);
|
|
185
|
-
return [uuidBytes, data.subarray(17)];
|
|
186
|
-
}
|
|
187
|
-
if (tag === 0x06) {
|
|
188
|
-
// pyatv: dummy parse as integer (little-endian 8 bytes)
|
|
189
|
-
const val = readLittleEndian(data, 1, 8);
|
|
190
|
-
return [val, data.subarray(9)];
|
|
191
|
-
}
|
|
192
|
-
if (tag >= 0x08 && tag <= 0x2f) return [tag - 8, data.subarray(1)];
|
|
193
|
-
if (tag === 0x35) {
|
|
194
|
-
const view = new DataView(data.buffer, data.byteOffset + 1, 4);
|
|
195
|
-
return [view.getFloat32(0, true), data.subarray(5)];
|
|
196
|
-
}
|
|
197
|
-
if (tag === 0x36) {
|
|
198
|
-
const view = new DataView(data.buffer, data.byteOffset + 1, 8);
|
|
199
|
-
return [view.getFloat64(0, true), data.subarray(9)];
|
|
200
|
-
}
|
|
201
|
-
if ((tag & 0xF0) === 0x30) {
|
|
202
|
-
const noOfBytes = 2 ** (tag & 0xF);
|
|
203
|
-
const val = readLittleEndian(data, 1, noOfBytes);
|
|
204
|
-
const sized = sizedInt(val, noOfBytes);
|
|
205
|
-
return [sized, data.subarray(1 + noOfBytes)];
|
|
206
|
-
}
|
|
207
|
-
if (tag >= 0x40 && tag <= 0x60) {
|
|
208
|
-
const length = tag - 0x40;
|
|
209
|
-
const str = new TextDecoder().decode(data.subarray(1, 1 + length));
|
|
210
|
-
return [str, data.subarray(1 + length)];
|
|
211
|
-
}
|
|
212
|
-
if (tag >= 0x61 && tag <= 0x64) {
|
|
213
|
-
const lenBytes = tag & 0xF;
|
|
214
|
-
const length = readLittleEndian(data, 1, lenBytes);
|
|
215
|
-
const str = new TextDecoder().decode(data.subarray(1 + lenBytes, 1 + lenBytes + length));
|
|
216
|
-
return [str, data.subarray(1 + lenBytes + length)];
|
|
217
|
-
}
|
|
218
|
-
if (tag >= 0x70 && tag <= 0x90) {
|
|
219
|
-
const length = tag - 0x70;
|
|
220
|
-
const bytes = data.subarray(1, 1 + length);
|
|
221
|
-
return [bytes, data.subarray(1 + length)];
|
|
222
|
-
}
|
|
223
|
-
if (tag >= 0x91 && tag <= 0x94) {
|
|
224
|
-
// number of length bytes = 1 << ((tag & 0xF) - 1)
|
|
225
|
-
const noOfBytes = 1 << ((tag & 0xF) - 1);
|
|
226
|
-
const length = readLittleEndian(data, 1, noOfBytes);
|
|
227
|
-
const start = 1 + noOfBytes;
|
|
228
|
-
return [data.subarray(start, start + length), data.subarray(start + length)];
|
|
229
|
-
}
|
|
230
|
-
if ((tag & 0xF0) === 0xD0) {
|
|
231
|
-
const count = tag & 0xF;
|
|
232
|
-
let ptr = data.subarray(1);
|
|
233
|
-
const output: any[] = [];
|
|
234
|
-
if (count === 0xF) {
|
|
235
|
-
// endless list
|
|
236
|
-
while (ptr[0] !== 0x03) {
|
|
237
|
-
const [val, rem] = _unpack(ptr, objectList);
|
|
238
|
-
output.push(val);
|
|
239
|
-
ptr = rem;
|
|
240
|
-
}
|
|
241
|
-
ptr = ptr.subarray(1); // skip terminator
|
|
242
|
-
} else {
|
|
243
|
-
for (let i = 0; i < count; i++) {
|
|
244
|
-
const [val, rem] = _unpack(ptr, objectList);
|
|
245
|
-
output.push(val);
|
|
246
|
-
ptr = rem;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
addToObjectList = false;
|
|
250
|
-
return [output, ptr];
|
|
251
|
-
}
|
|
252
|
-
if ((tag & 0xE0) === 0xE0) {
|
|
253
|
-
const count = tag & 0xF;
|
|
254
|
-
let ptr = data.subarray(1);
|
|
255
|
-
const output: Record<string, any> = {};
|
|
256
|
-
if (count === 0xF) {
|
|
257
|
-
// endless dict
|
|
258
|
-
while (ptr[0] !== 0x03) {
|
|
259
|
-
const [key, rem1] = _unpack(ptr, objectList);
|
|
260
|
-
const [val, rem2] = _unpack(rem1, objectList);
|
|
261
|
-
output[key] = val;
|
|
262
|
-
ptr = rem2;
|
|
263
|
-
}
|
|
264
|
-
ptr = ptr.subarray(1);
|
|
265
|
-
} else {
|
|
266
|
-
for (let i = 0; i < count; i++) {
|
|
267
|
-
const [key, rem1] = _unpack(ptr, objectList);
|
|
268
|
-
const [val, rem2] = _unpack(rem1, objectList);
|
|
269
|
-
output[key] = val;
|
|
270
|
-
ptr = rem2;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
addToObjectList = false;
|
|
274
|
-
return [output, ptr];
|
|
275
|
-
}
|
|
276
|
-
if (tag >= 0xA0 && tag <= 0xC0) {
|
|
277
|
-
const idx = tag - 0xA0;
|
|
278
|
-
return [objectList[idx], data.subarray(1)];
|
|
279
|
-
}
|
|
280
|
-
if (tag >= 0xC1 && tag <= 0xC4) {
|
|
281
|
-
const len = tag - 0xC0;
|
|
282
|
-
const uid = readLittleEndian(data, 1, len);
|
|
283
|
-
return [objectList[uid], data.subarray(1 + len)];
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
throw new TypeError(`Unknown tag 0x${tag.toString(16)}`);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function readLittleEndian(buf: Uint8Array, offset: number, len: number) {
|
|
290
|
-
let v = 0n;
|
|
291
|
-
for (let i = len - 1; i >= 0; i--) v = (v << 8n) | BigInt(buf[offset + i]);
|
|
292
|
-
return Number(v);
|
|
293
|
-
}
|
package/src/encoding/plist.ts
DELETED
package/src/encoding/tlv8.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
export const Flags = {
|
|
2
|
-
TransientPairing: 0x10
|
|
3
|
-
} as const;
|
|
4
|
-
|
|
5
|
-
export const Method = {
|
|
6
|
-
PairSetup: 0x00,
|
|
7
|
-
PairSetupWithAuth: 0x01,
|
|
8
|
-
PairVerify: 0x02,
|
|
9
|
-
AddPairing: 0x03,
|
|
10
|
-
RemovePairing: 0x04,
|
|
11
|
-
ListPairing: 0x05
|
|
12
|
-
} as const;
|
|
13
|
-
|
|
14
|
-
export const State = {
|
|
15
|
-
M1: 0x01,
|
|
16
|
-
M2: 0x02,
|
|
17
|
-
M3: 0x03,
|
|
18
|
-
M4: 0x04,
|
|
19
|
-
M5: 0x05,
|
|
20
|
-
M6: 0x06
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
export const Value = {
|
|
24
|
-
Method: 0x00,
|
|
25
|
-
Identifier: 0x01,
|
|
26
|
-
Salt: 0x02,
|
|
27
|
-
PublicKey: 0x03,
|
|
28
|
-
Proof: 0x04,
|
|
29
|
-
EncryptedData: 0x05,
|
|
30
|
-
State: 0x06,
|
|
31
|
-
Error: 0x07,
|
|
32
|
-
BackOff: 0x08,
|
|
33
|
-
Certificate: 0x09,
|
|
34
|
-
Signature: 0x0A,
|
|
35
|
-
Permissions: 0x0B,
|
|
36
|
-
FragmentData: 0x0C,
|
|
37
|
-
FragmentLast: 0x0D,
|
|
38
|
-
|
|
39
|
-
Name: 0x11,
|
|
40
|
-
Flags: 0x13
|
|
41
|
-
} as const;
|
|
42
|
-
|
|
43
|
-
export function bail(data: Map<number, Buffer>): never {
|
|
44
|
-
if (data.has(Value.BackOff)) {
|
|
45
|
-
const buffer = data.get(Value.BackOff);
|
|
46
|
-
const time = buffer.readUintLE(0, buffer.length);
|
|
47
|
-
|
|
48
|
-
throw new Error(`Device is busy, try again in ${time} seconds.`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (data.has(Value.Error)) {
|
|
52
|
-
throw new Error(`Device returned an error code: ${data.get(Value.Error).readUint8()}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
console.error(data);
|
|
56
|
-
|
|
57
|
-
throw new Error('Invalid response');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function encode(entries: [number, number | Buffer][]): Buffer {
|
|
61
|
-
const chunks: number[] = [];
|
|
62
|
-
|
|
63
|
-
for (const [type, valueRaw] of entries) {
|
|
64
|
-
let value: Buffer;
|
|
65
|
-
|
|
66
|
-
if (typeof valueRaw === 'number') {
|
|
67
|
-
value = Buffer.from([valueRaw]);
|
|
68
|
-
} else {
|
|
69
|
-
value = valueRaw;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let offset = 0;
|
|
73
|
-
|
|
74
|
-
do {
|
|
75
|
-
const len = Math.min(value.length - offset, 255);
|
|
76
|
-
chunks.push(type, len);
|
|
77
|
-
|
|
78
|
-
if (len > 0) {
|
|
79
|
-
for (let i = 0; i < len; i++) {
|
|
80
|
-
chunks.push(value[offset + i]);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
offset += len;
|
|
85
|
-
} while (offset < value.length);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return Buffer.from(chunks);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function decode(buf: Buffer): Map<number, Buffer> {
|
|
92
|
-
const map = new Map<number, Buffer>();
|
|
93
|
-
let i = 0;
|
|
94
|
-
|
|
95
|
-
while (i < buf.length) {
|
|
96
|
-
const type = buf[i++];
|
|
97
|
-
const len = buf[i++];
|
|
98
|
-
|
|
99
|
-
const value = (new Uint8Array(buf)).slice(i, i + len);
|
|
100
|
-
i += len;
|
|
101
|
-
|
|
102
|
-
const existing = map.get(type);
|
|
103
|
-
if (existing) {
|
|
104
|
-
map.set(type, Buffer.concat([existing, value]));
|
|
105
|
-
} else {
|
|
106
|
-
map.set(type, Buffer.from(value));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return map;
|
|
111
|
-
}
|
package/src/index.ts
DELETED
package/src/net/getLocalIP.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { networkInterfaces } from 'node:os';
|
|
2
|
-
|
|
3
|
-
export default function (): string {
|
|
4
|
-
const interfaces = networkInterfaces();
|
|
5
|
-
|
|
6
|
-
for (const name of Object.keys(interfaces)) {
|
|
7
|
-
const iface = interfaces[name];
|
|
8
|
-
|
|
9
|
-
if (!iface) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (const net of iface) {
|
|
14
|
-
if (net.internal || net.family !== 'IPv4') {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (net.address && net.address !== '127.0.0.1') {
|
|
19
|
-
return net.address;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
}
|
package/src/net/getMacAddress.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { networkInterfaces } from 'node:os';
|
|
2
|
-
|
|
3
|
-
export default function (): string {
|
|
4
|
-
const interfaces = networkInterfaces();
|
|
5
|
-
|
|
6
|
-
for (const name of Object.keys(interfaces)) {
|
|
7
|
-
const iface = interfaces[name];
|
|
8
|
-
|
|
9
|
-
if (!iface) {
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (const net of iface) {
|
|
14
|
-
if (net.internal || net.family !== 'IPv4') {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (net.mac && net.mac !== '00:00:00:00:00:00') {
|
|
19
|
-
return net.mac.toUpperCase();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
}
|
package/src/net/index.ts
DELETED