From 0b65e52b15ba389f61b07955510028e8cf5894c0 Mon Sep 17 00:00:00 2001 From: Tanner <88640606+Codetrauma@users.noreply.github.com> Date: Tue, 18 Mar 2025 01:35:06 -0700 Subject: [PATCH] feat: plugin for notarizing discord profiles (#15) Co-authored-by: Hendrik Eeckhaut --- .gitignore | 1 - examples/discord_dm/src/index.d.ts | 1 + examples/discord_profile/esbuild.js | 36 ++ examples/discord_profile/package-lock.json | 452 +++++++++++++++++++++ examples/discord_profile/package.json | 17 + examples/discord_profile/src/index.d.ts | 14 + examples/discord_profile/src/index.ts | 131 ++++++ examples/discord_profile/tsconfig.json | 14 + src/utils/hf.js | 14 + 9 files changed, 679 insertions(+), 1 deletion(-) create mode 100644 examples/discord_profile/esbuild.js create mode 100644 examples/discord_profile/package-lock.json create mode 100644 examples/discord_profile/package.json create mode 100644 examples/discord_profile/src/index.d.ts create mode 100644 examples/discord_profile/src/index.ts create mode 100644 examples/discord_profile/tsconfig.json diff --git a/.gitignore b/.gitignore index a543408..4429cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ build tlsn/ zip dist/ - diff --git a/examples/discord_dm/src/index.d.ts b/examples/discord_dm/src/index.d.ts index f153510..836eb4a 100644 --- a/examples/discord_dm/src/index.d.ts +++ b/examples/discord_dm/src/index.d.ts @@ -4,6 +4,7 @@ declare module 'main' { export function parseDiscordDm(): I32; export function three(): I32; export function config(): I32; + export function parseDiscordDm(): I32; } declare module 'extism:host' { diff --git a/examples/discord_profile/esbuild.js b/examples/discord_profile/esbuild.js new file mode 100644 index 0000000..e4a9f6d --- /dev/null +++ b/examples/discord_profile/esbuild.js @@ -0,0 +1,36 @@ +const esbuild = require('esbuild'); +const path = require('path'); +const { name } = require('./package.json'); +const { execSync } = require('child_process'); + +const outputDir = 'dist'; +const entryFile = 'src/index.ts'; +const outputFile = path.join(outputDir, 'index.js'); +const outputWasm = path.join(outputDir, `${name}.tlsn.wasm`); + +async function build() { + try { + await esbuild.build({ + entryPoints: [entryFile], + bundle: true, + outdir: outputDir, // Use outdir for directory output + sourcemap: true, + minify: false, // might want to use true for production build + format: 'cjs', // needs to be CJS for now + target: ['es2020'], // don't go over es2020 because quickjs doesn't support it + loader: {'.png': 'dataurl'} + }); + + console.log('esbuild completed successfully.'); + + // Run extism-js to generate the wasm file + const extismCommand = `extism-js ${outputFile} -i src/index.d.ts -o ${outputWasm}`; + execSync(extismCommand, { stdio: 'inherit' }); + console.log('extism-js completed successfully.'); + } catch (error) { + console.error('Build process failed:', error); + process.exit(1); + } +} + +build(); \ No newline at end of file diff --git a/examples/discord_profile/package-lock.json b/examples/discord_profile/package-lock.json new file mode 100644 index 0000000..c22314a --- /dev/null +++ b/examples/discord_profile/package-lock.json @@ -0,0 +1,452 @@ +{ + "name": "discord_profile", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "discord_profile", + "version": "1.0.0", + "license": "MIT", + "devDependencies": { + "@extism/js-pdk": "^1.0.1", + "esbuild": "^0.19.6", + "typescript": "^5.3.2" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.19.12.tgz", + "integrity": "sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.12.tgz", + "integrity": "sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.12.tgz", + "integrity": "sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.12.tgz", + "integrity": "sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.12.tgz", + "integrity": "sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.12.tgz", + "integrity": "sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.12.tgz", + "integrity": "sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.12.tgz", + "integrity": "sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.12.tgz", + "integrity": "sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.12.tgz", + "integrity": "sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.12.tgz", + "integrity": "sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.12.tgz", + "integrity": "sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.12.tgz", + "integrity": "sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.12.tgz", + "integrity": "sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.12.tgz", + "integrity": "sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.12.tgz", + "integrity": "sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.12.tgz", + "integrity": "sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.12.tgz", + "integrity": "sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.12.tgz", + "integrity": "sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.12.tgz", + "integrity": "sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.12.tgz", + "integrity": "sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.12.tgz", + "integrity": "sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.12.tgz", + "integrity": "sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@extism/js-pdk": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@extism/js-pdk/-/js-pdk-1.1.1.tgz", + "integrity": "sha512-VZLn/dX0ttA1uKk2PZeR/FL3N+nA1S5Vc7E5gdjkR60LuUIwCZT9cYON245V4HowHlBA7YOegh0TLjkx+wNbrA==", + "dev": true, + "dependencies": { + "urlpattern-polyfill": "^8.0.2" + } + }, + "node_modules/esbuild": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.12.tgz", + "integrity": "sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.19.12", + "@esbuild/android-arm": "0.19.12", + "@esbuild/android-arm64": "0.19.12", + "@esbuild/android-x64": "0.19.12", + "@esbuild/darwin-arm64": "0.19.12", + "@esbuild/darwin-x64": "0.19.12", + "@esbuild/freebsd-arm64": "0.19.12", + "@esbuild/freebsd-x64": "0.19.12", + "@esbuild/linux-arm": "0.19.12", + "@esbuild/linux-arm64": "0.19.12", + "@esbuild/linux-ia32": "0.19.12", + "@esbuild/linux-loong64": "0.19.12", + "@esbuild/linux-mips64el": "0.19.12", + "@esbuild/linux-ppc64": "0.19.12", + "@esbuild/linux-riscv64": "0.19.12", + "@esbuild/linux-s390x": "0.19.12", + "@esbuild/linux-x64": "0.19.12", + "@esbuild/netbsd-x64": "0.19.12", + "@esbuild/openbsd-x64": "0.19.12", + "@esbuild/sunos-x64": "0.19.12", + "@esbuild/win32-arm64": "0.19.12", + "@esbuild/win32-ia32": "0.19.12", + "@esbuild/win32-x64": "0.19.12" + } + }, + "node_modules/typescript": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/urlpattern-polyfill": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/urlpattern-polyfill/-/urlpattern-polyfill-8.0.2.tgz", + "integrity": "sha512-Qp95D4TPJl1kC9SKigDcqgyM2VDVO4RiJc2d4qe5GrYm+zbIQCWWKAFaJNQ4BhdFeDGwBmAxqJBwWSJDb9T3BQ==", + "dev": true + } + } +} diff --git a/examples/discord_profile/package.json b/examples/discord_profile/package.json new file mode 100644 index 0000000..a2d24e9 --- /dev/null +++ b/examples/discord_profile/package.json @@ -0,0 +1,17 @@ +{ + "name": "discord_profile", + "version": "1.0.0", + "description": "Demo TLSNotary plugin to notarize the ownership of a twitter profile", + "main": "src/index.ts", + "scripts": { + "build": "node esbuild.js" + }, + "keywords": [], + "author": "TLSNotary", + "license": "MIT", + "devDependencies": { + "@extism/js-pdk": "^1.0.1", + "esbuild": "^0.19.6", + "typescript": "^5.3.2" + } +} diff --git a/examples/discord_profile/src/index.d.ts b/examples/discord_profile/src/index.d.ts new file mode 100644 index 0000000..81ce3a5 --- /dev/null +++ b/examples/discord_profile/src/index.d.ts @@ -0,0 +1,14 @@ +declare module 'main' { + export function config(): I32; + export function start(): I32; + export function two(): I32; + export function three(): I32; + export function parseDiscordProfile(): I32; +} + +declare module 'extism:host' { + interface user { + redirect(ptr: I64): void; + notarize(ptr: I64): I64; + } +} diff --git a/examples/discord_profile/src/index.ts b/examples/discord_profile/src/index.ts new file mode 100644 index 0000000..e1b0f98 --- /dev/null +++ b/examples/discord_profile/src/index.ts @@ -0,0 +1,131 @@ +import { redirect, notarize, outputJSON, getLocalStorageByHost, getHeadersByHost } from '../../../src/utils/hf'; + +function isValidHost(urlString: string) { + const url = new URL(urlString); + return url.hostname === 'discord.com' || url.hostname === 'discord.gg' +} + +export function start() { + if (!isValidHost(Config.get('tabUrl'))) { + redirect('https://discord.com/channels/@me') + outputJSON(false); + return; + } + outputJSON(true); +} + + +export function two() { + const localStorage = getLocalStorageByHost('discord.com'); + let userId = localStorage.user_id_cache; + userId = userId.replace(/"/g, ""); + const headers = getHeadersByHost(`discord.com`) + console.log(JSON.stringify(headers)); + console.log(localStorage.user_id_cache); + if ( + !localStorage.user_id_cache || + !headers['Authorization'] + ) { + outputJSON(false); + return; + } + console.log('here'); + outputJSON({ + url: `https://discord.com/api/v9/users/${userId}/profile`, + method: 'GET', + headers: { + Host: 'discord.com', + Accept: '*/*', + 'Accept-Encoding': 'identity', + 'User-Agent': headers['User-Agent'], + Authorization: headers['Authorization'], + Connection: 'close' + }, + secretHeaders: [ + `Authorization: ${headers['Authorization']}` + ] + }); +} + +export function parseDiscordProfile() { + const bodyString = Host.inputString(); + const params = JSON.parse(bodyString); + + if (params.user?.username) { + const revealed = JSON.stringify({ + username: params.user.username, + global_name: params.user.global_name, + }).slice(1, -1); + + const selectionStart = bodyString.indexOf(revealed); + if (selectionStart === -1) { + outputJSON([bodyString]); + return; + } + + const selectionEnd = selectionStart + revealed.length; + const secretResps = [ + bodyString.substring(0, selectionStart), + bodyString.substring(selectionEnd), + ]; + outputJSON(secretResps); + } else { + outputJSON(false); + } +} + + +export function three() { + const params = JSON.parse(Host.inputString()); + + if (!params) { + outputJSON(false); + } else { + const id = notarize({ + ...params, + getSecretResponse: 'parseDiscordProfile' + }) + outputJSON(id); + } +} + + + +export function config() { + outputJSON({ + title: 'Discord Profile', + description: 'Notarize your Discord Profile', + + steps: [ + { + title: "Goto Discord", + description: "Log in to your discord if you haven't already", + cta: "Go to discord.com", + action: 'start' + }, + { + title: 'Collect credentials', + description: "Check Local Storage for User ID", + cta: 'Check localstorage', + action: 'two', + }, + { + title: 'Notarize Discord Profile', + cta: 'Notarize', + action: 'three', + prover: true, + } + ], + hostFunctions: ['redirect', 'notarize'], + headers: [ + "discord.com", + ], + localStorage: ['discord.com'], + requests: [ + { + url: `https://discord.com/api/v9/users/*/profile`, + method: 'GET', + }, + ], + }) +} diff --git a/examples/discord_profile/tsconfig.json b/examples/discord_profile/tsconfig.json new file mode 100644 index 0000000..a59c4c1 --- /dev/null +++ b/examples/discord_profile/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "lib": [], + "types": [ + "@extism/js-pdk" + ], + "noEmit": true, + "resolveJsonModule": true, + "esModuleInterop": true, + }, + "include": [ + "src/**/*" + ] +} \ No newline at end of file diff --git a/src/utils/hf.js b/src/utils/hf.js index 4b6cd2d..64acdbb 100644 --- a/src/utils/hf.js +++ b/src/utils/hf.js @@ -30,10 +30,24 @@ function getHeadersByHost(hostname) { return headers[hostname]; } +function getLocalStorageByHost(hostname) { + const localStorage = JSON.parse(Config.get('localStorage')); + if (!localStorage[hostname]) throw new Error(`cannot find local storage for ${hostname}`); + return localStorage[hostname]; +} + +function getSessionStorageByHost(hostname) { + const sessionStorage = JSON.parse(Config.get('sessionStorage')); + if (!sessionStorage[hostname]) throw new Error(`cannot find session storage for ${hostname}`); + return sessionStorage[hostname]; +} + module.exports = { redirect, notarize, outputJSON, getCookiesByHost, getHeadersByHost, + getLocalStorageByHost, + getSessionStorageByHost, };