2023-10-27 10:01:59 +00:00
|
|
|
import { sha256 } from 'js-sha256';
|
2023-11-02 14:15:18 +00:00
|
|
|
import { hexToBase91 } from '../utils';
|
2023-10-27 10:01:59 +00:00
|
|
|
|
|
|
|
interface AuthHeaders {
|
|
|
|
tokenSHA256: string;
|
|
|
|
keys: {
|
|
|
|
pubKey: string;
|
|
|
|
encPrivKey: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-06 16:20:54 +00:00
|
|
|
class Robot {
|
2024-01-06 12:33:57 +00:00
|
|
|
constructor(attributes?: Record<any, any>) {
|
|
|
|
if (attributes != null) {
|
|
|
|
this.token = attributes?.token ?? undefined;
|
2023-10-27 10:01:59 +00:00
|
|
|
this.tokenSHA256 =
|
2024-01-06 12:33:57 +00:00
|
|
|
attributes?.tokenSHA256 ?? (this.token != null ? hexToBase91(sha256(this.token)) : '');
|
|
|
|
this.pubKey = attributes?.pubKey ?? undefined;
|
|
|
|
this.encPrivKey = attributes?.encPrivKey ?? undefined;
|
2023-03-02 11:01:06 +00:00
|
|
|
}
|
2022-11-06 16:20:54 +00:00
|
|
|
}
|
2022-10-31 16:20:20 +00:00
|
|
|
|
2022-11-06 16:20:54 +00:00
|
|
|
public token?: string;
|
|
|
|
public bitsEntropy?: number;
|
|
|
|
public shannonEntropy?: number;
|
2023-05-06 13:42:48 +00:00
|
|
|
public tokenSHA256: string = '';
|
2023-05-05 10:12:38 +00:00
|
|
|
public pubKey?: string;
|
|
|
|
public encPrivKey?: string;
|
2022-11-06 16:20:54 +00:00
|
|
|
public stealthInvoices: boolean = true;
|
|
|
|
public activeOrderId?: number;
|
|
|
|
public lastOrderId?: number;
|
|
|
|
public earnedRewards: number = 0;
|
|
|
|
public tgEnabled: boolean = false;
|
|
|
|
public tgBotName: string = 'unknown';
|
|
|
|
public tgToken: string = 'unknown';
|
2023-10-27 10:01:59 +00:00
|
|
|
public loading: boolean = true;
|
2023-02-24 19:17:13 +00:00
|
|
|
public found: boolean = false;
|
2023-05-05 10:12:38 +00:00
|
|
|
public last_login: string = '';
|
2023-11-21 17:36:59 +00:00
|
|
|
public shortAlias: string = '';
|
2023-10-27 10:01:59 +00:00
|
|
|
|
2023-11-02 14:15:18 +00:00
|
|
|
update = (attributes: Record<string, any>): void => {
|
2023-10-27 10:01:59 +00:00
|
|
|
Object.assign(this, attributes);
|
|
|
|
};
|
|
|
|
|
|
|
|
getAuthHeaders = (): AuthHeaders | null => {
|
2024-01-06 12:33:57 +00:00
|
|
|
const tokenSHA256 = this.tokenSHA256 ?? '';
|
2023-10-27 10:01:59 +00:00
|
|
|
const encPrivKey = this.encPrivKey ?? '';
|
|
|
|
const pubKey = this.pubKey ?? '';
|
|
|
|
|
|
|
|
return {
|
|
|
|
tokenSHA256,
|
|
|
|
keys: {
|
|
|
|
pubKey: pubKey.split('\n').join('\\'),
|
|
|
|
encPrivKey: encPrivKey.split('\n').join('\\'),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2022-11-06 16:20:54 +00:00
|
|
|
}
|
2022-10-20 17:24:53 +00:00
|
|
|
|
|
|
|
export default Robot;
|