Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 169 additions & 291 deletions README.md

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# dependencies (bun install)
node_modules

# output
out
dist
*.tgz

# code coverage
coverage
*.lcov

# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# caches
.eslintcache
.cache
*.tsbuildinfo

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store

# Bun runtime (https://bun.sh/)
bun.lock
bun.lockb
28 changes: 28 additions & 0 deletions javascript/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
// Environment setup & latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
17 changes: 17 additions & 0 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "keyauth-js-example",
"module": "src/index.js",
"type": "module",
"devDependencies": {
"@types/bun": "latest",
"@types/qrcode": "^1.5.5"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"discord-interactions": "^4.1.1",
"qrcode": "^1.5.4",
"tweetnacl": "^1.0.3"
}
}
139 changes: 139 additions & 0 deletions javascript/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import KeyAuth from "./keyauth"
import { createInterface } from "readline/promises"

const readline = createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
})

const KeyAuthApp = new KeyAuth({
name: "",
ownerid: "",
version: "",
})

async function answer() {
try {
await KeyAuthApp.init()

console.log("[1] Login\n[2] Register\n[3] License\n[4] Upgrade")

const optionRaw = await readline.question("Select an option: ")
const option = parseInt(optionRaw)

let username = "",
password = "",
license = ""

switch (option) {
case 1:
username = await readline.question("Username: ")
password = await readline.question("Password: ")
await KeyAuthApp.login(username, password)
dashboard()
break

case 2:
username = await readline.question("Username: ")
password = await readline.question("Password: ")
license = await readline.question("License: ")
await KeyAuthApp.register(username, password, license)
dashboard()
break

case 3:
license = await readline.question("License: ")
await KeyAuthApp.license(license)
dashboard()
break

case 4:
username = await readline.question("Username: ")
license = await readline.question("License: ")
await KeyAuthApp.upgrade(username, license)
dashboard()
break

default:
console.log("Invalid option selected.")
break
}
} catch (error) {
if (error instanceof Error) {
console.error("An error occurred:", error.message)
} else {
console.error("An unknown error occurred:", error)
}
}
}

answer()

async function dashboard() {
await KeyAuthApp.fetchStats()
console.log("Application data:")
console.log(" App Version: ", KeyAuthApp.app_data?.app_ver)
console.log(" Customer panel: ", KeyAuthApp.app_data?.customer_panel)
console.log(" Number of Keys: ", KeyAuthApp.app_data?.numKeys)
console.log(" Number of Users: ", KeyAuthApp.app_data?.numUsers)
console.log(" Online Users: ", KeyAuthApp.app_data?.onlineUsers)

console.log("\nUser data:")
console.log(" Username: ", KeyAuthApp.user_data?.username)
console.log(" IP Address: ", KeyAuthApp.user_data?.ip)
console.log(" Hardware-id: ", KeyAuthApp.user_data?.hwid)

const subs = KeyAuthApp.user_data?.subscriptions || []

for (let i = 0; i < subs.length; i++) {
const sub = subs[i]
const expiry = new Date(Number(sub.expiry) * 1000)

console.log(
`[${i + 1}/${subs.length}] | Subscription: ${
sub.subscription
} - Expiry: ${expiry.toLocaleString()}`
)
}

console.log(
`Created at: ${new Date(
(KeyAuthApp.user_data?.createdate || 0) * 1000
).toLocaleString()}`
)
console.log(
`Last Login: ${new Date(
(KeyAuthApp.user_data?.lastlogin || 0) * 1000
).toLocaleString()}`
)
console.log(
`Expires: ${new Date(
(KeyAuthApp.user_data?.expires || 0) * 1000
).toLocaleString()}`
)

console.log("\n2-factor authentication:")
console.log("[1] Enable\n[2] Disable")

const optionRaw = await readline.question("Select an option: ")
const option = parseInt(optionRaw)

switch (option) {
case 1:
await KeyAuthApp.enable2fa()
break
case 2:
await KeyAuthApp.disable2fa()
break
default:
console.log("Invalid option selected.")
break
}

console.log("Closing app in 10 seconds...")
await new Promise(resolve => setTimeout(resolve, 10000))
readline.close()
await KeyAuthApp.logout()
process.exit(0)
}
Loading