@epicauth/sdk 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,94 @@
1
+
2
+ Elastic License 2.0
3
+
4
+ URL: https://www.elastic.co/licensing/elastic-license
5
+
6
+ ## Acceptance
7
+
8
+ By using the software, you agree to all of the terms and conditions below.
9
+
10
+ ## Copyright License
11
+
12
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
13
+ non-sublicensable, non-transferable license to use, copy, distribute, make
14
+ available, and prepare derivative works of the software, in each case subject to
15
+ the limitations and conditions below.
16
+
17
+ ## Limitations
18
+
19
+ You may not provide the software to third parties as a hosted or managed
20
+ service, where the service provides users with access to any substantial set of
21
+ the features or functionality of the software.
22
+
23
+ You may not move, change, disable, or circumvent the license key functionality
24
+ in the software, and you may not remove or obscure any functionality in the
25
+ software that is protected by the license key.
26
+
27
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
28
+ of the licensor in the software. Any use of the licensor’s trademarks is subject
29
+ to applicable law.
30
+
31
+ ## Patents
32
+
33
+ The licensor grants you a license, under any patent claims the licensor can
34
+ license, or becomes able to license, to make, have made, use, sell, offer for
35
+ sale, import and have imported the software, in each case subject to the
36
+ limitations and conditions in this license. This license does not cover any
37
+ patent claims that you cause to be infringed by modifications or additions to
38
+ the software. If you or your company make any written claim that the software
39
+ infringes or contributes to infringement of any patent, your patent license for
40
+ the software granted under these terms ends immediately. If your company makes
41
+ such a claim, your patent license ends immediately for work on behalf of your
42
+ company.
43
+
44
+ ## Notices
45
+
46
+ You must ensure that anyone who gets a copy of any part of the software from you
47
+ also gets a copy of these terms.
48
+
49
+ If you modify the software, you must include in any modified copies of the
50
+ software prominent notices stating that you have modified the software.
51
+
52
+ ## No Other Rights
53
+
54
+ These terms do not imply any licenses other than those expressly granted in
55
+ these terms.
56
+
57
+ ## Termination
58
+
59
+ If you use the software in violation of these terms, such use is not licensed,
60
+ and your licenses will automatically terminate. If the licensor provides you
61
+ with a notice of your violation, and you cease all violation of this license no
62
+ later than 30 days after you receive that notice, your licenses will be
63
+ reinstated retroactively. However, if you violate these terms after such
64
+ reinstatement, any additional violation of these terms will cause your licenses
65
+ to terminate automatically and permanently.
66
+
67
+ ## No Liability
68
+
69
+ *As far as the law allows, the software comes as is, without any warranty or
70
+ condition, and the licensor will not be liable to you for any damages arising
71
+ out of these terms or the use or nature of the software, under any kind of
72
+ legal claim.*
73
+
74
+ ## Definitions
75
+
76
+ The **licensor** is the entity offering these terms, and the **software** is the
77
+ software the licensor makes available under these terms, including any portion
78
+ of it.
79
+
80
+ **you** refers to the individual or entity agreeing to these terms.
81
+
82
+ **your company** is any legal entity, sole proprietorship, or other kind of
83
+ organization that you work for, plus all organizations that have control over,
84
+ are under the control of, or are under common control with that
85
+ organization. **control** means ownership of substantially all the assets of an
86
+ entity, or the power to direct its management and policies by vote, contract, or
87
+ otherwise. Control can be direct or indirect.
88
+
89
+ **your licenses** are all the licenses granted to you for the software under
90
+ these terms.
91
+
92
+ **use** means anything you do with the software requiring one of your licenses.
93
+
94
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # epicauth-ts-example
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.3.13. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
@@ -0,0 +1,45 @@
1
+ import type { EpicAuthAppData, EpicAuthOptions, EpicAuthUserData } from "./types/types";
2
+ import type { LicenseOptions, LoginOptions } from "./types/inputs";
3
+ export default class EpicAuth {
4
+ private name;
5
+ private ownerid;
6
+ private version;
7
+ private hash_to_check?;
8
+ private url;
9
+ private path?;
10
+ private exitOnError?;
11
+ private sessionid?;
12
+ private initialized;
13
+ private public_key;
14
+ private loggingEnabled;
15
+ user_data: EpicAuthUserData | null;
16
+ app_data: EpicAuthAppData | null;
17
+ constructor(options: EpicAuthOptions);
18
+ Init(): Promise<undefined>;
19
+ /**
20
+ * Login to EpicAuth using a username and password.
21
+ *
22
+ * @param username User's username.
23
+ * @param password User's password.
24
+ * @param code Optional 2FA code if exist.
25
+ * @param hwid Optional custom HWID.
26
+ *
27
+ */
28
+ login({ username, password, code, hwid }: LoginOptions): Promise<undefined>;
29
+ /**
30
+ * Login to EpicAuth Using a license key.
31
+ *
32
+ * @param license License key
33
+ * @param code Optional 2FA code if exist.
34
+ * @param hwid Optional custom HWID.
35
+ */
36
+ license({ license, code, hwid }: LicenseOptions): Promise<undefined>;
37
+ checkinit(): Promise<undefined>;
38
+ getHWID(): string;
39
+ private fail;
40
+ private sleep;
41
+ private request;
42
+ private logEvent;
43
+ private redactField;
44
+ private load_user_data;
45
+ }
package/dist/client.js ADDED
@@ -0,0 +1,351 @@
1
+ import { EpicAuthError } from "./errors";
2
+ import crypto from "crypto";
3
+ import * as ed from "@noble/ed25519";
4
+ import fs from "fs";
5
+ import { execSync, exec } from "child_process";
6
+ import os from "os";
7
+ import { createInterface } from "readline";
8
+ import path from "node:path";
9
+ import { sha512 } from "@noble/hashes/sha2.js";
10
+ ed.hashes.sha512 = (...msgs) => sha512(ed.etc.concatBytes(...msgs));
11
+ const readline = createInterface({
12
+ input: process.stdin,
13
+ output: process.stdout,
14
+ terminal: false,
15
+ });
16
+ export default class EpicAuth {
17
+ name;
18
+ ownerid;
19
+ version;
20
+ hash_to_check;
21
+ url = "https://epicauth.cc/api/1.3/";
22
+ path;
23
+ exitOnError = true;
24
+ sessionid;
25
+ initialized = false;
26
+ public_key = "95b38710f40927b16528a073b87d942e03bd4578d49963a19ebae177945f89ac";
27
+ loggingEnabled = true;
28
+ user_data = null;
29
+ app_data = null;
30
+ constructor(options) {
31
+ this.name = options.name;
32
+ this.ownerid = options.ownerid;
33
+ this.version = options.version;
34
+ this.hash_to_check = options.hash_to_check;
35
+ this.url = options.url ?? "https://epicauth.cc/api/1.3/";
36
+ this.path = options.path;
37
+ this.loggingEnabled = options.loggingEnabled ?? true;
38
+ this.exitOnError = options.exitOnError ?? true;
39
+ if (!this.name || !this.ownerid || !this.version) {
40
+ throw new Error("Name, ownerid, and version are required");
41
+ }
42
+ }
43
+ async Init() {
44
+ if (!this.sessionid && this.initialized) {
45
+ return this.fail("Application already initialized", 0);
46
+ }
47
+ let token = "";
48
+ if (this.path) {
49
+ try {
50
+ token = fs.readFileSync(this.path, "utf-8").trim();
51
+ }
52
+ catch (error) {
53
+ return this.fail(`Failed to read file at path ${this.path}: ${error}`, 0);
54
+ }
55
+ }
56
+ const body = {
57
+ "type": "init",
58
+ "ownerid": this.ownerid,
59
+ "version": this.version,
60
+ "name": this.name,
61
+ "hash": this.hash_to_check,
62
+ ...this.path && {
63
+ "token": token,
64
+ "thash": crypto.createHash("sha256").update(token).digest("hex"),
65
+ }
66
+ };
67
+ const response = await this.request(body);
68
+ if (response === "EpicAuth_Invalid") {
69
+ return this.fail("This application does not exist");
70
+ }
71
+ if (response["message"] === "invalidver") {
72
+ if ("download" in response) {
73
+ console.log("Your application is outdated.");
74
+ exec(`start ${response["download"]}`, (error) => {
75
+ if (error) {
76
+ return this.fail(`Failed to open the download link:${error}`);
77
+ }
78
+ });
79
+ return this.fail('use latest update');
80
+ }
81
+ else {
82
+ return this.fail("Your application is outdated and no download link was provided, contact the owner for the latest app version.");
83
+ }
84
+ }
85
+ if (response['success'] === false) {
86
+ return this.fail(response['message']);
87
+ }
88
+ if ("sessionid" in response) {
89
+ this.sessionid = response.sessionid;
90
+ this.initialized = true;
91
+ }
92
+ }
93
+ /**
94
+ * Login to EpicAuth using a username and password.
95
+ *
96
+ * @param username User's username.
97
+ * @param password User's password.
98
+ * @param code Optional 2FA code if exist.
99
+ * @param hwid Optional custom HWID.
100
+ *
101
+ */
102
+ async login({ username, password, code, hwid }) {
103
+ this.checkinit();
104
+ if (!hwid)
105
+ hwid = this.getHWID();
106
+ const body = {
107
+ "type": "login",
108
+ "name": this.name,
109
+ "ownerid": this.ownerid,
110
+ "sessionid": this.sessionid,
111
+ "username": username,
112
+ "pass": password,
113
+ "hwid": hwid,
114
+ ...code && { "code": code },
115
+ };
116
+ const response = await this.request(body);
117
+ if (response["success"] === true) {
118
+ console.log(response["message"]);
119
+ this.load_user_data(response["info"]);
120
+ }
121
+ else {
122
+ console.log(response["message"]);
123
+ return this.fail(response['message']);
124
+ }
125
+ }
126
+ /**
127
+ * Login to EpicAuth Using a license key.
128
+ *
129
+ * @param license License key
130
+ * @param code Optional 2FA code if exist.
131
+ * @param hwid Optional custom HWID.
132
+ */
133
+ async license({ license, code, hwid }) {
134
+ this.checkinit();
135
+ if (!hwid)
136
+ hwid = this.getHWID();
137
+ const body = {
138
+ "type": "license",
139
+ "name": this.name,
140
+ "ownerid": this.ownerid,
141
+ "sessionid": this.sessionid,
142
+ "key": license,
143
+ "hwid": hwid,
144
+ ...code && { "code": code },
145
+ };
146
+ const response = await this.request(body);
147
+ if (response["success"] === true) {
148
+ console.log(response["message"]);
149
+ this.load_user_data(response["info"]);
150
+ }
151
+ else {
152
+ console.log(response["message"]);
153
+ return this.fail(response['message']);
154
+ }
155
+ }
156
+ async checkinit() {
157
+ if (!this.sessionid && !this.initialized) {
158
+ return this.fail("You need to run the EpicAuthApp.init(); function before any other EpicAuth functions");
159
+ }
160
+ }
161
+ getHWID() {
162
+ const platform = os.platform();
163
+ try {
164
+ switch (platform) {
165
+ case "linux":
166
+ // Linux: (machine-id)
167
+ try {
168
+ const machineId = fs.readFileSync("/etc/machine-id", "utf-8").trim();
169
+ if (machineId && machineId.length > 10) {
170
+ return machineId;
171
+ }
172
+ }
173
+ catch {
174
+ // Fallback
175
+ try {
176
+ const dbus = fs.readFileSync("/var/lib/dbus/machine-id", "utf-8").trim();
177
+ if (dbus)
178
+ return dbus;
179
+ }
180
+ catch { }
181
+ }
182
+ break;
183
+ case "win32":
184
+ // Windows: Machine GUID
185
+ try {
186
+ const guid = execSync('reg query "HKLM\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid', { stdio: "pipe" }).toString();
187
+ const match = guid.match(/MachineGuid\s+REG_SZ\s+([a-zA-Z0-9-]+)/);
188
+ if (match && match[1]) {
189
+ return match[1];
190
+ }
191
+ }
192
+ catch { }
193
+ // Fallback to SID
194
+ try {
195
+ const user = os.userInfo().username;
196
+ const sidOutput = execSync(`wmic useraccount where name='${user}' get sid`, { stdio: "pipe" }).toString();
197
+ const sid = sidOutput.split("\n")[1]?.trim();
198
+ if (sid && sid.length > 10)
199
+ return sid;
200
+ }
201
+ catch { }
202
+ break;
203
+ case "darwin":
204
+ // macOS: Serial Number
205
+ try {
206
+ const serial = execSync("ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformSerialNumber")
207
+ .toString()
208
+ .split("=")[1]
209
+ ?.trim()
210
+ .replace(/"/g, "");
211
+ if (serial)
212
+ return serial;
213
+ }
214
+ catch { }
215
+ break;
216
+ }
217
+ }
218
+ catch (error) {
219
+ console.warn("⚠️ Primary HWID method failed, using fallback");
220
+ }
221
+ const fallback = [
222
+ os.hostname(),
223
+ os.userInfo().username,
224
+ os.arch(),
225
+ os.cpus()[0]?.model || "",
226
+ crypto.randomUUIDv7()
227
+ ].join("|");
228
+ return crypto
229
+ .createHash("sha256")
230
+ .update(fallback)
231
+ .digest("hex")
232
+ .substring(0, 32);
233
+ }
234
+ async fail(message, ms = 5000) {
235
+ if (this.exitOnError) {
236
+ console.error(message);
237
+ await this.sleep(ms);
238
+ process.exit(1);
239
+ }
240
+ throw new EpicAuthError(message);
241
+ }
242
+ async sleep(ms) {
243
+ return new Promise((resolve) => setTimeout(resolve, ms));
244
+ }
245
+ async request(body) {
246
+ try {
247
+ const params = new URLSearchParams();
248
+ for (const [key, value] of Object.entries(body)) {
249
+ if (value !== undefined) {
250
+ params.append(key, String(value));
251
+ }
252
+ }
253
+ const response = await fetch(this.url, {
254
+ method: "POST",
255
+ headers: {
256
+ "Content-Type": "application/x-www-form-urlencoded",
257
+ },
258
+ body: params.toString(),
259
+ });
260
+ if (!response.ok) {
261
+ return this.fail(`HTTP ${response.status}`);
262
+ }
263
+ const rawBody = await response.text();
264
+ if (rawBody === "EpicAuth_Invalid") {
265
+ return rawBody;
266
+ }
267
+ const data = JSON.parse(rawBody);
268
+ const excludedfuncs = ["file", "log", "2faenable", "2fadisable"];
269
+ if (excludedfuncs.includes(body.type)) {
270
+ return data;
271
+ }
272
+ const signature = response.headers.get("x-signature-ed25519");
273
+ const timestamp = response.headers.get("x-signature-timestamp");
274
+ if (!signature || !timestamp) {
275
+ return this.fail("Missing signature or timestamp in response headers");
276
+ }
277
+ const server_time = new Date(Number(timestamp) * 1000).toUTCString();
278
+ const current_time = new Date().toUTCString();
279
+ const buffer_seconds = 5; // Allowable time difference in seconds
280
+ const time_difference = Math.abs(new Date(server_time).getTime() - new Date(current_time).getTime()) / 1000;
281
+ if (time_difference > buffer_seconds + 20) {
282
+ return this.fail(`Time difference is too large: ${time_difference} seconds, try syncing your date and time settings.`);
283
+ }
284
+ const message = new TextEncoder().encode(timestamp + rawBody);
285
+ const signatureBytes = ed.etc.hexToBytes(signature);
286
+ const publicKeyBytes = ed.etc.hexToBytes(this.public_key);
287
+ const valid = await ed.verify(signatureBytes, message, publicKeyBytes);
288
+ if (!valid) {
289
+ return this.fail("Signature checksum failed. Request was tampered with or session ended most likely.", 3000);
290
+ }
291
+ this.logEvent(JSON.stringify(data) + "\n");
292
+ return data;
293
+ }
294
+ catch (error) {
295
+ return this.fail(`Unexpected error: ${error}`);
296
+ }
297
+ }
298
+ logEvent(message) {
299
+ console.log(message);
300
+ if (!this.loggingEnabled)
301
+ return;
302
+ const executable = process.argv[1] ?? "unknown";
303
+ const exeName = executable.split("\\").pop() ?? executable.split("/").pop() ?? "unknown";
304
+ const logDirectory = path.join(os.homedir(), ".epicauth", "logs", exeName);
305
+ try {
306
+ if (!fs.existsSync(logDirectory)) {
307
+ fs.mkdirSync(logDirectory, { recursive: true });
308
+ }
309
+ const logFileName = `${new Date().toLocaleDateString("en-US", { month: "short", day: "2-digit", year: "numeric" }).replace(/ /g, "_")}_logs.txt`;
310
+ const logFilePath = `${logDirectory}/${logFileName}`;
311
+ // Redact sensitive fields
312
+ message = this.redactField(message, "sessionid");
313
+ message = this.redactField(message, "ownerid");
314
+ message = this.redactField(message, "app");
315
+ message = this.redactField(message, "version");
316
+ message = this.redactField(message, "fileid");
317
+ message = this.redactField(message, "webhooks");
318
+ message = this.redactField(message, "nonce");
319
+ const logMessage = `[${new Date().toISOString()}] [${exeName}] ${message}\n`;
320
+ fs.appendFileSync(logFilePath, logMessage, "utf-8");
321
+ }
322
+ catch (error) {
323
+ if (error instanceof Error) {
324
+ console.error(`Error logging data: ${error.message}`);
325
+ }
326
+ else {
327
+ console.error("Error logging data: Unknown error");
328
+ }
329
+ }
330
+ }
331
+ redactField(content, field) {
332
+ const regex = new RegExp(`"${field}":\\s*".*?"`, "g");
333
+ return content.replace(regex, `"${field}": "[REDACTED]"`);
334
+ }
335
+ load_user_data(data) {
336
+ const subscription = data.subscriptions[0];
337
+ if (!subscription) {
338
+ return this.fail("User has no subscriptions.");
339
+ }
340
+ this.user_data = {
341
+ username: data.username,
342
+ ip: data.ip,
343
+ hwid: data.hwid ?? "N/A",
344
+ expires: Number(subscription.expiry),
345
+ createdate: Number(data.createdate),
346
+ lastlogin: Number(data.lastlogin),
347
+ subscription: subscription.subscription,
348
+ subscriptions: data.subscriptions,
349
+ };
350
+ }
351
+ }
@@ -0,0 +1,4 @@
1
+ export declare class EpicAuthError extends Error {
2
+ status?: number | undefined;
3
+ constructor(message: string, status?: number | undefined);
4
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ export class EpicAuthError extends Error {
2
+ status;
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.status = status;
6
+ this.name = "EpicAuthError";
7
+ }
8
+ }
@@ -0,0 +1,2 @@
1
+ import EpicAuth from "./client";
2
+ export default EpicAuth;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import EpicAuth from "./client";
2
+ export default EpicAuth;
@@ -0,0 +1,11 @@
1
+ export interface LoginOptions {
2
+ username: string;
3
+ password: string;
4
+ code?: string;
5
+ hwid?: string;
6
+ }
7
+ export interface LicenseOptions {
8
+ license: string;
9
+ code?: string;
10
+ hwid?: string;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
1
+ export interface DownloadResponse {
2
+ success: boolean;
3
+ code: number;
4
+ message: string;
5
+ download: string;
6
+ nonce: string;
7
+ ownerid: string;
8
+ }
9
+ export interface InitResponse {
10
+ success: boolean;
11
+ code: number;
12
+ message: string;
13
+ sessionid: string;
14
+ appinfo: {
15
+ numUsers: string;
16
+ numOnlineUsers: string;
17
+ numKeys: string;
18
+ version: string;
19
+ customerPanelLink: string;
20
+ };
21
+ newSession: boolean;
22
+ nonce: string;
23
+ ownerid: string;
24
+ }
25
+ export interface LoginResponse {
26
+ success: boolean;
27
+ code: number;
28
+ message: string;
29
+ info: {
30
+ username: string;
31
+ subscriptions: {
32
+ subscription: string;
33
+ key: string;
34
+ expiry: string;
35
+ timeleft: number;
36
+ level: string;
37
+ }[];
38
+ ip: string;
39
+ hwid: string | undefined;
40
+ createdate: string | number;
41
+ lastlogin: string;
42
+ };
43
+ nonce: string;
44
+ ownerid: string;
45
+ }
46
+ export interface LicenseResponse {
47
+ success: boolean;
48
+ code: number;
49
+ message: string;
50
+ info: {
51
+ username: string;
52
+ subscriptions: {
53
+ subscription: string;
54
+ key: string;
55
+ expiry: string;
56
+ timeleft: number;
57
+ level: string;
58
+ }[];
59
+ ip: string;
60
+ hwid: string | undefined;
61
+ createdate: string | number;
62
+ lastlogin: string;
63
+ };
64
+ nonce: string;
65
+ ownerid: string;
66
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ export interface EpicAuthOptions {
2
+ name: string;
3
+ ownerid: string;
4
+ version: string;
5
+ hash_to_check?: string;
6
+ url?: string;
7
+ path?: string;
8
+ exitOnError?: boolean;
9
+ loggingEnabled?: boolean;
10
+ }
11
+ export interface ResolvedEpicAuthOptions extends EpicAuthOptions {
12
+ exitOnError: boolean;
13
+ loggingEnabled: boolean;
14
+ url: string;
15
+ public_key: string;
16
+ }
17
+ export interface ApiResponse<T = unknown> {
18
+ success: boolean;
19
+ message: string;
20
+ data: T;
21
+ }
22
+ export interface EpicAuthUserData {
23
+ username: string;
24
+ ip: string;
25
+ hwid: string;
26
+ expires: number;
27
+ createdate: number;
28
+ lastlogin: number;
29
+ subscription: string;
30
+ subscriptions: EpicAuthSubscription[];
31
+ }
32
+ export interface EpicAuthSubscription {
33
+ subscription: string;
34
+ key: string;
35
+ expiry: string;
36
+ timeleft: number;
37
+ level: string;
38
+ }
39
+ export interface EpicAuthAppData {
40
+ numUsers: number;
41
+ numKeys: number;
42
+ app_ver: string;
43
+ customer_panel: string;
44
+ onlineUsers: number;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@epicauth/sdk",
3
+ "version": "0.1.3",
4
+ "description": "EpicAuth SDK for Node.js and Bun",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "dev": "bun --watch src/index.ts"
23
+ },
24
+ "private": false,
25
+ "license": "Elastic-2.0",
26
+ "dependencies": {
27
+ "@noble/ed25519": "^3.1.0",
28
+ "@noble/hashes": "^2.2.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/bun": "latest",
32
+ "typescript": "^5.9.0"
33
+ }
34
+ }