herdr-remote-relay 0.3.23 → 0.3.24
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/auth-store.js
CHANGED
|
@@ -17,6 +17,19 @@ function nowIso(now = Date.now()) {
|
|
|
17
17
|
function validHostId(value) {
|
|
18
18
|
return typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(value);
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* What a person reads off one screen and types on another: six characters,
|
|
22
|
+
* without 0/O or 1/I/L to confuse. Cutting base64 and dropping its `-` and `_`
|
|
23
|
+
* made one code in seven shorter than six, and some too short to pair at all.
|
|
24
|
+
*/
|
|
25
|
+
const PAIR_CODE_ALPHABET = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
|
|
26
|
+
const PAIR_CODE_LENGTH = 6;
|
|
27
|
+
function newPairCode() {
|
|
28
|
+
let code = '';
|
|
29
|
+
for (let i = 0; i < PAIR_CODE_LENGTH; i += 1)
|
|
30
|
+
code += PAIR_CODE_ALPHABET[crypto.randomInt(PAIR_CODE_ALPHABET.length)];
|
|
31
|
+
return code;
|
|
32
|
+
}
|
|
20
33
|
class AuthStore {
|
|
21
34
|
stateFile;
|
|
22
35
|
pairingTtlMs;
|
|
@@ -119,7 +132,7 @@ class AuthStore {
|
|
|
119
132
|
this.cleanup(now);
|
|
120
133
|
let code;
|
|
121
134
|
do {
|
|
122
|
-
code =
|
|
135
|
+
code = newPairCode();
|
|
123
136
|
} while ([...this.pairings.values()].some((pairing) => equalHash(pairing.codeHash, hash(code))));
|
|
124
137
|
const expiresAt = now + this.pairingTtlMs;
|
|
125
138
|
this.pairings.set(code, {
|