plogme 1.0.6 → 2.0.1

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.
@@ -1,296 +0,0 @@
1
- /**
2
- * Package integrity & attribution guard.
3
- *
4
- * Verifies at runtime that this copy is the genuine, un-rebranded
5
- * `plogme` distribution and that the attribution-required license is
6
- * intact. If the package identity has been renamed/stripped
7
- * (the usual result of AI-assisted rebranding), premium features are
8
- * disabled with a loud warning so the stolen copy visibly degrades
9
- * instead of quietly becoming a "free rebrand".
10
- *
11
- * A remote attestation layer sits on top: on socket connect the client
12
- * phones home to bailey.crysnovax.link with its package identity and a
13
- * machine fingerprint. The worker answers "genuine", "revoked", or
14
- * "rebranded"; "revoked" / "rebranded" disable premium features and can
15
- * be issued remotely by the operator at any time.
16
- *
17
- * DEVELOPER ESCAPE HATCH (so the maintainer never locks themself out):
18
- * Set CRYSNOVAX_TRUST_MODE=1 in the environment to bypass the local
19
- * integrity checks entirely. Use this when you are actively editing
20
- * the package (e.g. with an AI assistant) and a check trips on a
21
- * legitimate edit. Rebranders can set it too — but at that point they
22
- * are deliberately tampering, which the license already prohibits.
23
- *
24
- * Anti-evasion notes:
25
- * - The expected identity is stored ENCODED and only decoded at runtime,
26
- * so naive find-and-replace / "remove every mention of crysnovax"
27
- * rewrites miss it.
28
- * - This module is imported from several unrelated entry points
29
- * (socket factory, base socket, message composer, message sender), so
30
- * removing one hook leaves the others active.
31
- * - The checks never throw and never break legitimate installs: a
32
- * manifest that cannot be read — or a worker that cannot be reached —
33
- * is treated as genuine rather than risking false-positive degradation.
34
- */
35
- import { readFileSync } from 'fs';
36
- import { createHash } from 'node:crypto';
37
- import os from 'node:os';
38
- import { createRequire } from 'node:module';
39
- import { DONATE_URL, LIBRARY_NAME } from '../Defaults/index.js';
40
-
41
- const nodeRequire = createRequire(import.meta.url);
42
- const decode = b64 => Buffer.from(b64, 'base64').toString('utf8');
43
-
44
- // ─── Encoded brand identity (decoded below at runtime) ──────────────────────
45
- const EXPECTED = {
46
- // plogme
47
- name: 'cGxvZ21l',
48
- // plogme
49
- author: 'cGxvZ21l',
50
- // https://web.crysnovax.link
51
- site: 'aHR0cHM6Ly93ZWIuY3J5c25vdmF4Lmxpbms=',
52
- // SEE LICENSE IN LICENSE
53
- licenseId: 'U0VFIExJQ0VOU0UgSU4gTElDRU5TRQ==',
54
- // crysnovax/bailey
55
- libraryName: 'Y3J5c25vdmF4L2JhaWxleQ==',
56
- // Crysnovax Source License v1.0 (canary phrase inside LICENSE)
57
- licenseCanary: 'Q3J5c25vdmF4IFNvdXJjZSBMaWNlbnNlIHYxLjA=',
58
- // https://bailey.crysnovax.link/api/v1/verify
59
- verifyUrl: 'aHR0cHM6Ly9iYWlsZXkuY3J5c25vdmF4LmxpbmsvYXBpL3YxL3ZlcmlmeQ=='
60
- };
61
-
62
- /** Public brand string used for messages (decoded once). */
63
- export const getBrandName = () => decode(EXPECTED.name);
64
-
65
- /** Developer escape hatch — set to '1' while actively editing the package. */
66
- export const isTrustMode = () => process.env.CRYSNOVAX_TRUST_MODE === '1';
67
-
68
- let cachedReport = null;
69
-
70
- /**
71
- * Returns { genuine, reasons, warnings } for this copy. Memoized per process.
72
- * - CRYSNOVAX_TRUST_MODE=1 → genuine (developer mode)
73
- * - manifest readable + all checks pass → genuine: true
74
- * - manifest readable + identity mismatch → genuine: false (reasons)
75
- * - cosmetic drift (URL/canary touched) → genuine: true (warnings only)
76
- * - manifest unreadable (unusual packaging) → genuine: true (no false positives)
77
- */
78
- export const getIntegrityReport = () => {
79
- if (cachedReport) {
80
- return cachedReport;
81
- }
82
- if (isTrustMode()) {
83
- cachedReport = {
84
- genuine: true,
85
- reasons: ['trust mode'],
86
- warnings: ['CRYSNOVAX_TRUST_MODE=1 is set — integrity checks bypassed (developer mode)']
87
- };
88
- return cachedReport;
89
- }
90
- const reasons = [];
91
- const warnings = [];
92
- let manifest = null;
93
- try {
94
- // lib/Utils/integrity.js → ../../package.json = package root manifest
95
- manifest = nodeRequire('../../package.json');
96
- }
97
- catch {
98
- // manifest not resolvable — never degrade on packaging oddities alone
99
- }
100
- if (manifest) {
101
- const author = typeof manifest.author === 'string'
102
- ? manifest.author
103
- : manifest.author?.name;
104
- // Hard identity checks — these are what define a rebrand.
105
- if (manifest.name !== decode(EXPECTED.name)) {
106
- reasons.push(`package renamed to "${manifest.name}"`);
107
- }
108
- if (author !== decode(EXPECTED.author)) {
109
- reasons.push('author attribution removed');
110
- }
111
- if (manifest.license !== decode(EXPECTED.licenseId)) {
112
- reasons.push(`license swapped to "${manifest.license}"`);
113
- }
114
- }
115
- // LICENSE file must exist and carry the license identifier canary
116
- try {
117
- const licenseText = readFileSync(new URL('../../LICENSE', import.meta.url), 'utf8');
118
- if (!licenseText.includes(decode(EXPECTED.licenseCanary))) {
119
- // Missing canary = likely edited LICENSE; still licensable, so warn
120
- warnings.push('license file was edited (canary phrase missing)');
121
- }
122
- }
123
- catch {
124
- reasons.push('license file missing');
125
- }
126
- // Brand constants — cosmetic drift warns but never disables features,
127
- // so maintainers editing defaults with an AI don't lock themselves out.
128
- if (DONATE_URL !== decode(EXPECTED.site)) {
129
- warnings.push('attribution URL changed');
130
- }
131
- if (LIBRARY_NAME !== decode(EXPECTED.libraryName)) {
132
- warnings.push('library identity constant changed');
133
- }
134
- cachedReport = {
135
- genuine: reasons.length === 0,
136
- reasons,
137
- warnings
138
- };
139
- return cachedReport;
140
- };
141
-
142
- let rebrandWarned = false;
143
- let warningsShown = false;
144
-
145
- /**
146
- * Logs a loud, one-time warning when this copy fails the integrity check.
147
- * Also surfaces cosmetic warnings once (genuine but drifted) so the
148
- * maintainer knows a check was soft-tripped. Returns the report.
149
- */
150
- export const warnIfRebranded = (logger) => {
151
- const report = getIntegrityReport();
152
- if (!report.warnings.length && !rebrandWarned) {
153
- return report;
154
- }
155
- const log = (level, message) => {
156
- if (logger && typeof logger[level] === 'function') {
157
- logger[level]({ reasons: report.reasons, warnings: report.warnings }, message);
158
- }
159
- else {
160
- console.warn('\n' + message + '\n');
161
- }
162
- };
163
- if (report.warnings.length && !warningsShown) {
164
- warningsShown = true;
165
- log('warn',
166
- `⚙ ${getBrandName()} integrity: ${report.warnings.join('; ')}. ` +
167
- `Features stay enabled; if this was an accidental edit, set CRYSNOVAX_TRUST_MODE=1 while developing.`);
168
- }
169
- if (!report.genuine && !rebrandWarned) {
170
- rebrandWarned = true;
171
- log('warn',
172
- `✖ UNAUTHORIZED REBRANDED COPY DETECTED — this is not an official ` +
173
- `${getBrandName()} distribution (${report.reasons.join('; ')}). ` +
174
- `Rebranding or removing attribution violates the ${decode(EXPECTED.licenseCanary)}. ` +
175
- `Premium features are disabled on this copy. Install the genuine package: ` +
176
- `https://www.npmjs.com/package/${getBrandName()}`);
177
- }
178
- return report;
179
- };
180
-
181
- // ─── Remote attestation (bailey.crysnovax.link) ─────────────────────────────
182
-
183
- let fingerprint = null;
184
- const getFingerprint = () => {
185
- if (fingerprint) {
186
- return fingerprint;
187
- }
188
- const cpu = os.cpus?.()?.[0]?.model || 'unknown-cpu';
189
- const raw = [
190
- os.hostname(),
191
- os.platform(),
192
- os.arch(),
193
- cpu,
194
- process.version
195
- ].join('|');
196
- fingerprint = createHash('sha256').update(raw).digest('hex').slice(0, 32);
197
- return fingerprint;
198
- };
199
-
200
- let remoteRevoked = false;
201
- let remoteChecked = false;
202
- let remoteError = false;
203
- let remoteWarned = false;
204
-
205
- /** Current remote state: 'genuine' | 'revoked' | 'unknown'. */
206
- export const getRemoteStatus = () => {
207
- if (!remoteChecked || remoteError) {
208
- return 'unknown';
209
- }
210
- return remoteRevoked ? 'revoked' : 'genuine';
211
- };
212
-
213
- /**
214
- * Phones home once per process. NEVER throws and FAILS OPEN: any network
215
- * error, timeout, or malformed reply leaves premium features enabled —
216
- * only an explicit revoked/rebranded verdict disables them.
217
- */
218
- export const refreshRemoteStatus = async (logger) => {
219
- if (remoteChecked) {
220
- return getRemoteStatus();
221
- }
222
- remoteChecked = true;
223
- try {
224
- let pkg = null;
225
- let version = '';
226
- try {
227
- pkg = nodeRequire('../../package.json');
228
- version = pkg?.version || '';
229
- }
230
- catch {
231
- // manifest unreadable — still send what we know
232
- }
233
- const controller = new AbortController();
234
- const timer = setTimeout(() => controller.abort(), 4000);
235
- try {
236
- const res = await fetch(decode(EXPECTED.verifyUrl), {
237
- method: 'POST',
238
- headers: { 'Content-Type': 'application/json' },
239
- body: JSON.stringify({
240
- package: pkg?.name || '',
241
- version,
242
- fingerprint: getFingerprint()
243
- }),
244
- signal: controller.signal
245
- });
246
- if (!res.ok) {
247
- remoteError = true;
248
- return 'unknown';
249
- }
250
- const body = await res.json();
251
- if (body?.status === 'revoked' || body?.status === 'rebranded') {
252
- remoteRevoked = true;
253
- if (!remoteWarned) {
254
- remoteWarned = true;
255
- const message = `✖ THIS INSTALL HAS BEEN REVOKED (${body.status}) — premium features are disabled.`;
256
- if (logger && typeof logger.warn === 'function') {
257
- logger.warn({ status: body.status }, message);
258
- }
259
- else {
260
- console.warn('\n' + message + '\n');
261
- }
262
- }
263
- }
264
- }
265
- finally {
266
- clearTimeout(timer);
267
- }
268
- }
269
- catch {
270
- // fail open — network error/timeout never bricks a genuine install
271
- remoteError = true;
272
- }
273
- return getRemoteStatus();
274
- };
275
-
276
- /**
277
- * Gate for premium features: returns true only on a genuine copy that has
278
- * not been remotely revoked. On a rebranded/revoked copy, warns once and
279
- * returns false so the feature degrades to its non-premium behavior.
280
- */
281
- export const premiumEnabled = (logger) => {
282
- // Remote revocation wins (its warning was already emitted by refreshRemoteStatus)
283
- if (remoteRevoked) {
284
- return false;
285
- }
286
- const report = getIntegrityReport();
287
- if (!report.genuine) {
288
- warnIfRebranded(logger);
289
- return false;
290
- }
291
- // Genuine but drifted — surface the warnings once, keep features on
292
- if (report.warnings.length) {
293
- warnIfRebranded(logger);
294
- }
295
- return true;
296
- };