39 lines
1.3 KiB
JavaScript
Executable File
39 lines
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict'
|
|
// Reads credentials from .env and generates src/api/credentials.ts with
|
|
// XOR-encoded values. The generated file is gitignored — run this before
|
|
// building. The obfuscation pipeline further scrambles the decoded logic.
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const envPath = path.join(__dirname, '../.env')
|
|
require('dotenv').config({ path: envPath })
|
|
|
|
// 8-byte rolling key used for XOR encoding
|
|
const KEY = [0x4B, 0x7E, 0x23, 0x91, 0x5A, 0x3F, 0xC2, 0x8D]
|
|
|
|
function encode(str) {
|
|
return Array.from(str).map((c, i) => c.charCodeAt(0) ^ KEY[i % KEY.length])
|
|
}
|
|
|
|
const fields = {
|
|
_EI: process.env.SC_CLIENT_ID ?? '',
|
|
_ES: process.env.SC_CLIENT_SECRET ?? '',
|
|
_ER: process.env.SC_REDIRECT_URI ?? 'http://127.0.0.1:52123/callback',
|
|
}
|
|
|
|
const out = [
|
|
'// AUTO-GENERATED by scripts/encode-creds.js — do not edit or commit',
|
|
`const _K: number[] = [${KEY.join(', ')}]`,
|
|
`export function _cx(e: number[]): string {`,
|
|
` return e.map((c, i) => String.fromCharCode(c ^ _K[i % _K.length])).join('')`,
|
|
`}`,
|
|
...Object.entries(fields).map(
|
|
([name, val]) => `export const ${name}: number[] = [${encode(val).join(', ')}]`
|
|
),
|
|
].join('\n') + '\n'
|
|
|
|
const outPath = path.join(__dirname, '../src/api/credentials.ts')
|
|
fs.writeFileSync(outPath, out, 'utf8')
|
|
console.log('[encode-creds] wrote src/api/credentials.ts')
|