added decoder
This commit is contained in:
parent
104bebb783
commit
748cce0eeb
4 changed files with 22 additions and 0 deletions
17
apps/stock/data-ingestion/src/handlers/te/shared/decode.ts
Normal file
17
apps/stock/data-ingestion/src/handlers/te/shared/decode.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { inflate } from 'pako';
|
||||
|
||||
/**
|
||||
* Decodes TE obfuscated data: base64 decode -> XOR with key -> inflate -> JSON parse
|
||||
*/
|
||||
export function decodeTEData<T = unknown>(b64Data: string, key: string): T | null {
|
||||
try {
|
||||
const raw = Array.from(atob(b64Data), (c) => c.charCodeAt(0));
|
||||
const keyBytes = Array.from(new TextEncoder().encode(key));
|
||||
const keyLen = keyBytes.length;
|
||||
const xored = new Uint8Array(raw.map((byte, i) => byte ^ (keyBytes[i % keyLen] ?? 0)));
|
||||
|
||||
return JSON.parse(inflate(xored, { to: 'string' }));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export * from './config';
|
||||
export * from './decode';
|
||||
export * from './types';
|
||||
3
bun.lock
3
bun.lock
|
|
@ -15,6 +15,7 @@
|
|||
"@testcontainers/mongodb": "^10.7.2",
|
||||
"@testcontainers/postgresql": "^10.7.2",
|
||||
"@types/bun": "^1.2.17",
|
||||
"@types/pako": "^2.0.4",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"@types/yup": "^0.32.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
||||
|
|
@ -1015,6 +1016,8 @@
|
|||
|
||||
"@types/node": ["@types/node@20.19.4", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-OP+We5WV8Xnbuvw0zC2m4qfB/BJvjyCwtNjhHdJxV1639SGSKrLmJkc3fMnp2Qy8nJyHp8RO6umxELN/dS1/EA=="],
|
||||
|
||||
"@types/pako": ["@types/pako@2.0.4", "", {}, "sha512-VWDCbrLeVXJM9fihYodcLiIv0ku+AlOa/TQ1SvYOaBuyrSKgEcro95LJyIsJ4vSo6BXIxOKxiJAat04CmST9Fw=="],
|
||||
|
||||
"@types/pg": ["@types/pg@8.15.4", "", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^2.2.0" } }, "sha512-I6UNVBAoYbvuWkkU3oosC8yxqH21f4/Jc4DK71JLG3dT2mdlGe1z+ep/LQGXaKaOgcvUrsQoPRqfgtMcvZiJhg=="],
|
||||
|
||||
"@types/prop-types": ["@types/prop-types@15.7.15", "", {}, "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw=="],
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@
|
|||
"@testcontainers/mongodb": "^10.7.2",
|
||||
"@testcontainers/postgresql": "^10.7.2",
|
||||
"@types/bun": "^1.2.17",
|
||||
"@types/pako": "^2.0.4",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"@types/yup": "^0.32.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue