From 748cce0eeb0d706e7851e9a3ebacec420be1d5cb Mon Sep 17 00:00:00 2001 From: Boki Date: Sun, 29 Mar 2026 22:22:12 -0400 Subject: [PATCH] added decoder --- .../src/handlers/te/shared/decode.ts | 17 +++++++++++++++++ .../src/handlers/te/shared/index.ts | 1 + bun.lock | 3 +++ package.json | 1 + 4 files changed, 22 insertions(+) create mode 100644 apps/stock/data-ingestion/src/handlers/te/shared/decode.ts diff --git a/apps/stock/data-ingestion/src/handlers/te/shared/decode.ts b/apps/stock/data-ingestion/src/handlers/te/shared/decode.ts new file mode 100644 index 0000000..14b1b72 --- /dev/null +++ b/apps/stock/data-ingestion/src/handlers/te/shared/decode.ts @@ -0,0 +1,17 @@ +import { inflate } from 'pako'; + +/** + * Decodes TE obfuscated data: base64 decode -> XOR with key -> inflate -> JSON parse + */ +export function decodeTEData(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; + } +} diff --git a/apps/stock/data-ingestion/src/handlers/te/shared/index.ts b/apps/stock/data-ingestion/src/handlers/te/shared/index.ts index 6f3dade..f367657 100644 --- a/apps/stock/data-ingestion/src/handlers/te/shared/index.ts +++ b/apps/stock/data-ingestion/src/handlers/te/shared/index.ts @@ -1,2 +1,3 @@ export * from './config'; +export * from './decode'; export * from './types'; \ No newline at end of file diff --git a/bun.lock b/bun.lock index 8c120f7..b7c6d5a 100644 --- a/bun.lock +++ b/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=="], diff --git a/package.json b/package.json index d0e3cba..d418456 100644 --- a/package.json +++ b/package.json @@ -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",