@schuttdev/gigai 0.1.0-beta.1 → 0.1.0-beta.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/chunk-77HVPD4G.js +43 -0
- package/dist/chunk-J4PH7NSH.js +4333 -0
- package/dist/chunk-MKHJTSVH.js +35 -0
- package/dist/chunk-VXSUF3QQ.js +75 -0
- package/dist/chunk-W7QWQLMN.js +44 -0
- package/dist/dist-FGVVXLRN.js +61105 -0
- package/dist/index.js +12 -4148
- package/dist/pairing-IGMDVOIZ-2GDM2ZTC.js +12 -0
- package/dist/store-Y4V3TOYJ-N237XIVJ.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// ../server/node_modules/nanoid/index.js
|
|
4
|
+
import { webcrypto as crypto } from "crypto";
|
|
5
|
+
|
|
6
|
+
// ../server/node_modules/nanoid/url-alphabet/index.js
|
|
7
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
8
|
+
|
|
9
|
+
// ../server/node_modules/nanoid/index.js
|
|
10
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
11
|
+
var pool;
|
|
12
|
+
var poolOffset;
|
|
13
|
+
function fillPool(bytes) {
|
|
14
|
+
if (!pool || pool.length < bytes) {
|
|
15
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
16
|
+
crypto.getRandomValues(pool);
|
|
17
|
+
poolOffset = 0;
|
|
18
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
19
|
+
crypto.getRandomValues(pool);
|
|
20
|
+
poolOffset = 0;
|
|
21
|
+
}
|
|
22
|
+
poolOffset += bytes;
|
|
23
|
+
}
|
|
24
|
+
function nanoid(size = 21) {
|
|
25
|
+
fillPool(size |= 0);
|
|
26
|
+
let id = "";
|
|
27
|
+
for (let i = poolOffset - size; i < poolOffset; i++) {
|
|
28
|
+
id += urlAlphabet[pool[i] & 63];
|
|
29
|
+
}
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
nanoid
|
|
35
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
nanoid
|
|
4
|
+
} from "./chunk-MKHJTSVH.js";
|
|
5
|
+
|
|
6
|
+
// ../server/dist/chunk-RZTCSUFS.mjs
|
|
7
|
+
var AuthStore = class {
|
|
8
|
+
pairingCodes = /* @__PURE__ */ new Map();
|
|
9
|
+
sessions = /* @__PURE__ */ new Map();
|
|
10
|
+
cleanupInterval;
|
|
11
|
+
constructor() {
|
|
12
|
+
this.cleanupInterval = setInterval(() => this.cleanup(), 6e4);
|
|
13
|
+
}
|
|
14
|
+
// Pairing codes
|
|
15
|
+
addPairingCode(code, ttlSeconds) {
|
|
16
|
+
const entry = {
|
|
17
|
+
code,
|
|
18
|
+
expiresAt: Date.now() + ttlSeconds * 1e3,
|
|
19
|
+
used: false
|
|
20
|
+
};
|
|
21
|
+
this.pairingCodes.set(code, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
}
|
|
24
|
+
getPairingCode(code) {
|
|
25
|
+
return this.pairingCodes.get(code);
|
|
26
|
+
}
|
|
27
|
+
markPairingCodeUsed(code) {
|
|
28
|
+
const entry = this.pairingCodes.get(code);
|
|
29
|
+
if (entry) {
|
|
30
|
+
entry.used = true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Sessions
|
|
34
|
+
createSession(orgUuid, ttlSeconds) {
|
|
35
|
+
const session = {
|
|
36
|
+
id: nanoid(32),
|
|
37
|
+
orgUuid,
|
|
38
|
+
token: nanoid(48),
|
|
39
|
+
expiresAt: Date.now() + ttlSeconds * 1e3,
|
|
40
|
+
lastActivity: Date.now()
|
|
41
|
+
};
|
|
42
|
+
this.sessions.set(session.token, session);
|
|
43
|
+
return session;
|
|
44
|
+
}
|
|
45
|
+
getSession(token) {
|
|
46
|
+
const session = this.sessions.get(token);
|
|
47
|
+
if (session) {
|
|
48
|
+
session.lastActivity = Date.now();
|
|
49
|
+
}
|
|
50
|
+
return session;
|
|
51
|
+
}
|
|
52
|
+
// Cleanup
|
|
53
|
+
cleanup() {
|
|
54
|
+
const now = Date.now();
|
|
55
|
+
for (const [key, code] of this.pairingCodes) {
|
|
56
|
+
if (code.expiresAt < now) {
|
|
57
|
+
this.pairingCodes.delete(key);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const [key, session] of this.sessions) {
|
|
61
|
+
if (session.expiresAt < now) {
|
|
62
|
+
this.sessions.delete(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
destroy() {
|
|
67
|
+
clearInterval(this.cleanupInterval);
|
|
68
|
+
this.pairingCodes.clear();
|
|
69
|
+
this.sessions.clear();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
AuthStore
|
|
75
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ErrorCode,
|
|
4
|
+
GigaiError,
|
|
5
|
+
encrypt
|
|
6
|
+
} from "./chunk-J4PH7NSH.js";
|
|
7
|
+
import {
|
|
8
|
+
nanoid
|
|
9
|
+
} from "./chunk-MKHJTSVH.js";
|
|
10
|
+
|
|
11
|
+
// ../server/dist/chunk-54TEF6CS.mjs
|
|
12
|
+
var PAIRING_CODE_LENGTH = 8;
|
|
13
|
+
var PAIRING_CODE_CHARS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
14
|
+
function generatePairingCode(store, ttlSeconds) {
|
|
15
|
+
let code = "";
|
|
16
|
+
const bytes = nanoid(PAIRING_CODE_LENGTH);
|
|
17
|
+
for (let i = 0; i < PAIRING_CODE_LENGTH; i++) {
|
|
18
|
+
code += PAIRING_CODE_CHARS[bytes.charCodeAt(i) % PAIRING_CODE_CHARS.length];
|
|
19
|
+
}
|
|
20
|
+
store.addPairingCode(code, ttlSeconds);
|
|
21
|
+
return code;
|
|
22
|
+
}
|
|
23
|
+
function validateAndPair(store, code, orgUuid, encryptionKey, serverFingerprint) {
|
|
24
|
+
const entry = store.getPairingCode(code.toUpperCase());
|
|
25
|
+
if (!entry) {
|
|
26
|
+
throw new GigaiError(ErrorCode.PAIRING_INVALID, "Invalid pairing code");
|
|
27
|
+
}
|
|
28
|
+
if (entry.used) {
|
|
29
|
+
throw new GigaiError(ErrorCode.PAIRING_USED, "Pairing code already used");
|
|
30
|
+
}
|
|
31
|
+
if (entry.expiresAt < Date.now()) {
|
|
32
|
+
throw new GigaiError(ErrorCode.PAIRING_EXPIRED, "Pairing code expired");
|
|
33
|
+
}
|
|
34
|
+
store.markPairingCodeUsed(code.toUpperCase());
|
|
35
|
+
return encrypt(
|
|
36
|
+
{ orgUuid, serverFingerprint, createdAt: Date.now() },
|
|
37
|
+
encryptionKey
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
generatePairingCode,
|
|
43
|
+
validateAndPair
|
|
44
|
+
};
|