dsh-quay-bot 1.0.2 → 1.0.6
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/README.md +28 -105
- package/botscreen/requirements.txt +1 -1
- package/client.js +123 -53
- package/cordis.patch.yml +1 -1
- package/host/api.js +4 -0
- package/host/remote.js +285 -8
- package/host/screen.js +22 -86
- package/package.json +34 -32
- package/remote/bin/dsh-remote.mjs +435 -0
- package/remote/package.json +27 -0
- package/remote/src/config.mjs +183 -0
- package/remote/src/crypto.mjs +220 -0
- package/remote/src/keys.mjs +226 -0
- package/remote/src/proxy.mjs +1028 -0
- package/remote/src/sessions.mjs +163 -0
- package/remote/src/shim.js +838 -0
- package/remote/src/supervisor.mjs +207 -0
- package/remote/src/tunnel.mjs +533 -0
- package/remote/src/upstream.mjs +403 -0
- package/remote/src/util.mjs +149 -0
- package/remote/src/ws.mjs +313 -0
- package/LICENSE +0 -21
- package/avatar/build.mjs +0 -81
- package/avatar/gallery/droid.json +0 -14
- package/avatar/gallery/ghost.json +0 -14
- package/avatar/gallery/grok-pod.json +0 -14
- package/avatar/gallery/guardian.json +0 -14
- package/avatar/gallery/mecha.json +0 -14
- package/avatar/gallery/mochi.json +0 -14
- package/avatar/gallery/neko.json +0 -14
- package/avatar/gallery/orbiter.json +0 -14
- package/avatar/gallery/relay.json +0 -14
- package/avatar/gallery/spark.json +0 -14
- package/avatar/src/bot/clay.ts +0 -135
- package/avatar/src/bot/effects.ts +0 -100
- package/avatar/src/bot/grok-bot.ts +0 -626
- package/avatar/src/bot/index.ts +0 -15
- package/avatar/src/bot/palettes.ts +0 -62
- package/avatar/src/bot/ring.ts +0 -219
- package/avatar/src/bot/scheduler.ts +0 -239
- package/avatar/src/bot/shapes.ts +0 -277
- package/avatar/src/bot/spring.ts +0 -196
- package/avatar/src/core/color.ts +0 -92
- package/avatar/src/core/eyes.ts +0 -297
- package/avatar/src/core/field.ts +0 -482
- package/avatar/src/core/frame.ts +0 -655
- package/avatar/src/core/fx.ts +0 -375
- package/avatar/src/core/index.ts +0 -49
- package/avatar/src/core/paint.ts +0 -331
- package/avatar/src/core/path.ts +0 -495
- package/avatar/src/core/pose.ts +0 -581
- package/avatar/src/core/svg.ts +0 -98
- package/avatar/src/core/types.ts +0 -153
- package/avatar/src/core/validate.ts +0 -296
- package/avatar/src/core/volume.ts +0 -681
- package/avatar/src/entry.ts +0 -260
- package/bin/doctor.mjs +0 -148
- package/botscreen/requirements-offline.txt +0 -11
- package/market/index.json +0 -41
- package/vendor/pip/pip-25.1.1-py3-none-any.whl +0 -0
- package/vendor/pip/setuptools-78.1.1-py3-none-any.whl +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 握手挑战 + 加密会话存储。
|
|
3
|
+
*/
|
|
4
|
+
import { randomBytes } from 'node:crypto'
|
|
5
|
+
import { b64u, unb64u } from './util.mjs'
|
|
6
|
+
import { ReplayWindow, newSessionId } from './crypto.mjs'
|
|
7
|
+
|
|
8
|
+
export class SessionStore {
|
|
9
|
+
constructor({ ttlMs = 12 * 3_600_000, challengeTtlMs = 120_000, logger } = {}) {
|
|
10
|
+
this.ttlMs = ttlMs
|
|
11
|
+
this.challengeTtlMs = challengeTtlMs
|
|
12
|
+
this.logger = logger
|
|
13
|
+
this.sessions = new Map()
|
|
14
|
+
this.challenges = new Map()
|
|
15
|
+
this.timer = setInterval(() => this.prune(), 60_000)
|
|
16
|
+
this.timer.unref?.()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
issueChallenge(identity) {
|
|
20
|
+
const nonce = randomBytes(16)
|
|
21
|
+
const record = {
|
|
22
|
+
nonce: b64u(nonce),
|
|
23
|
+
kid: identity.kid,
|
|
24
|
+
spk: identity.spki,
|
|
25
|
+
createdAt: Date.now(),
|
|
26
|
+
expiresAt: Date.now() + this.challengeTtlMs,
|
|
27
|
+
used: false,
|
|
28
|
+
}
|
|
29
|
+
this.challenges.set(record.nonce, record)
|
|
30
|
+
this.prune()
|
|
31
|
+
return record
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 单次消费:返回挑战记录或 null。 */
|
|
35
|
+
consumeChallenge(nonceB64, kid) {
|
|
36
|
+
const record = this.challenges.get(nonceB64)
|
|
37
|
+
if (!record) return null
|
|
38
|
+
if (record.used || record.expiresAt < Date.now()) {
|
|
39
|
+
this.challenges.delete(nonceB64)
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
if (kid && record.kid !== kid) return null
|
|
43
|
+
record.used = true
|
|
44
|
+
this.challenges.delete(nonceB64)
|
|
45
|
+
return record
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
create({ sid = newSessionId(), kid, keys, pskKid, remote = null, userAgent = null }) {
|
|
49
|
+
const now = Date.now()
|
|
50
|
+
const session = {
|
|
51
|
+
sid,
|
|
52
|
+
sidB64: b64u(sid),
|
|
53
|
+
kid,
|
|
54
|
+
pskKid,
|
|
55
|
+
keys,
|
|
56
|
+
c2sWindow: new ReplayWindow(1024),
|
|
57
|
+
s2cSeq: 0,
|
|
58
|
+
createdAt: now,
|
|
59
|
+
lastSeen: now,
|
|
60
|
+
expiresAt: now + this.ttlMs,
|
|
61
|
+
renewKid: pskKid,
|
|
62
|
+
remote,
|
|
63
|
+
userAgent,
|
|
64
|
+
ws: null,
|
|
65
|
+
bytesIn: 0,
|
|
66
|
+
bytesOut: 0,
|
|
67
|
+
}
|
|
68
|
+
this.sessions.set(session.sidB64, session)
|
|
69
|
+
return session
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get(sidB64, { touch = true } = {}) {
|
|
73
|
+
const session = this.sessions.get(sidB64)
|
|
74
|
+
if (!session) return null
|
|
75
|
+
const now = Date.now()
|
|
76
|
+
if (session.expiresAt < now) {
|
|
77
|
+
this.sessions.delete(sidB64)
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
if (touch) session.lastSeen = now
|
|
81
|
+
return session
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getBySidBuffer(sid) {
|
|
85
|
+
return this.get(b64u(sid))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
delete(sidB64) {
|
|
89
|
+
const session = this.sessions.get(sidB64)
|
|
90
|
+
if (!session) return
|
|
91
|
+
try {
|
|
92
|
+
session.ws?.close?.(1000, 'session closed')
|
|
93
|
+
} catch {}
|
|
94
|
+
this.sessions.delete(sidB64)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setRenewal(session, next) {
|
|
98
|
+
session.renewKid = next.kid
|
|
99
|
+
session.renewPsk = next.psk
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 取续期载荷;取过一次就清掉,避免每帧重复。 */
|
|
103
|
+
takeRenewal(session, currentPskKid) {
|
|
104
|
+
if (!session.renewPsk || session.renewKid === currentPskKid) return null
|
|
105
|
+
const payload = { kid: session.renewKid, psk: session.renewPsk }
|
|
106
|
+
session.renewPsk = null
|
|
107
|
+
return payload
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
nextSeq(session) {
|
|
111
|
+
const seq = session.s2cSeq
|
|
112
|
+
if (seq > 0xffffffff) throw new Error('会话序号耗尽,需要重新握手')
|
|
113
|
+
session.s2cSeq = seq + 1
|
|
114
|
+
return seq
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
prune(now = Date.now()) {
|
|
118
|
+
for (const [key, session] of this.sessions) {
|
|
119
|
+
if (session.expiresAt < now) this.sessions.delete(key)
|
|
120
|
+
}
|
|
121
|
+
for (const [key, record] of this.challenges) {
|
|
122
|
+
if (record.expiresAt < now) this.challenges.delete(key)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
all() {
|
|
127
|
+
return [...this.sessions.values()]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
list() {
|
|
131
|
+
return [...this.sessions.values()].map((session) => ({
|
|
132
|
+
sid: session.sidB64,
|
|
133
|
+
kid: session.kid,
|
|
134
|
+
pskKid: session.pskKid,
|
|
135
|
+
createdAt: new Date(session.createdAt).toISOString(),
|
|
136
|
+
lastSeen: new Date(session.lastSeen).toISOString(),
|
|
137
|
+
expiresAt: new Date(session.expiresAt).toISOString(),
|
|
138
|
+
remote: session.remote,
|
|
139
|
+
userAgent: session.userAgent,
|
|
140
|
+
ws: Boolean(session.ws),
|
|
141
|
+
bytesIn: session.bytesIn,
|
|
142
|
+
bytesOut: session.bytesOut,
|
|
143
|
+
}))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get size() {
|
|
147
|
+
return this.sessions.size
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
close() {
|
|
151
|
+
clearInterval(this.timer)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function sidFromHeader(value) {
|
|
156
|
+
if (typeof value !== 'string' || value.length === 0) return null
|
|
157
|
+
try {
|
|
158
|
+
const raw = unb64u(value)
|
|
159
|
+
return raw.length === 16 ? value : null
|
|
160
|
+
} catch {
|
|
161
|
+
return null
|
|
162
|
+
}
|
|
163
|
+
}
|