1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.doKeysMatch = exports.matchingNibbleLength = exports.nibblesToBuffer = exports.bufferToNibbles = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function bufferToNibbles(key) {
|
10 | var bkey = Buffer.from(key);
|
11 | var nibbles = [];
|
12 | for (var i = 0; i < bkey.length; i++) {
|
13 | var q = i * 2;
|
14 | nibbles[q] = bkey[i] >> 4;
|
15 | ++q;
|
16 | nibbles[q] = bkey[i] % 16;
|
17 | }
|
18 | return nibbles;
|
19 | }
|
20 | exports.bufferToNibbles = bufferToNibbles;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function nibblesToBuffer(arr) {
|
27 | var buf = Buffer.alloc(arr.length / 2);
|
28 | for (var i = 0; i < buf.length; i++) {
|
29 | var q = i * 2;
|
30 | buf[i] = (arr[q] << 4) + arr[++q];
|
31 | }
|
32 | return buf;
|
33 | }
|
34 | exports.nibblesToBuffer = nibblesToBuffer;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function matchingNibbleLength(nib1, nib2) {
|
42 | var i = 0;
|
43 | while (nib1[i] === nib2[i] && nib1.length > i) {
|
44 | i++;
|
45 | }
|
46 | return i;
|
47 | }
|
48 | exports.matchingNibbleLength = matchingNibbleLength;
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function doKeysMatch(keyA, keyB) {
|
55 | var length = matchingNibbleLength(keyA, keyB);
|
56 | return length === keyA.length && length === keyB.length;
|
57 | }
|
58 | exports.doKeysMatch = doKeysMatch;
|
59 |
|
\ | No newline at end of file |