-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
136 lines (116 loc) · 5.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const got = require('got');
const projects = require('./lib/projects');
/**
* @class SMSPVAClient
* @description Wrapper class for the smspva.com API
* @param {object} [opts] - Config options
* @param {string} [opts.key=process.env.SMSPVA_KEY] - API key for smspva
*/
class SMSPVAClient {
constructor(opts = {}) {
const { key = process.env.SMSPVA_KEY } = opts;
this._key = key;
this._client = got.extend({
json: true,
retry: 5,
});
}
/** @typedef {Object} SMSPVANumber
* @property {String} id Unique identifier for this number, will be used to retrieve the SMS Code sent to it
* @property {String} number The raw 9-digit string that makes up the virtual number
* @property {String} response Indicates success or failure acquiring the virtual number
*/
/**
* @description Acquires a virtual number based on provided service (see supported services)
* @returns {SMSPVANumber}
*/
async getNumber(opts = {}) {
const { country, service } = opts;
const provider = projects.serviceToPID[service];
const { body } = await this._client(`http://smspva.com/priemnik.php?metod=get_number&country=${country}&service=${provider}&apikey=${this._key}`);
return body;
}
/**
* @description Returns User's balance
* @returns {number} User's balance
*/
async getBalance() {
const { body } = await this._client(`http://smspva.com/priemnik.php?metod=getBalance&service=opt4&apikey=${this._key}`);
const currentBalance = Number(body.balance);
return currentBalance;
}
/**
* @description Polls smspva API for response containing SMS verification code, returns this code.
* @param {string} id Unique identifier for the number issued by smspva
* @param {string} country Country identifier
* @param {string} service Service the number issued from smspva is being used for
* @param {number} [retries=20] Retry count (Optional)
* @returns {string} SMS Code
*/
async getSMS(opts = {}) {
const { id, country = 'US', service = 'google', retries = 20 } = opts;
const provider = projects.serviceToPID[service];
const { body } = await this._client(`http://smspva.com/priemnik.php?metod=get_sms&country=${country}&service=${provider}&id=${id}&apikey=${this._key}`);
const { response } = body;
// SMS has not been found yet
if (response === '2') {
await wait(20000);
return await this.getSMS(id, country, service, retries - 1);
}
if (response === '1') {
return body.sms;
}
}
/**
* @description Bans a particular number, given its unique identifier
* @param {string} id Unique identifier for the number
* @param {string} country Origin country for the number
* @param {string} service Service number is being used for
* @returns {boolean} Whether number was banned succesfully or not
*/
async ban(opts = {}) {
const { id, country = 'US', service } = opts;
const provider = projects.serviceToPID[service];
const { body } = await this._client(`http://smspva.com/priemnik.php?metod=denial&country=${country}&service=${provider}&apikey=${this._key}&id=${id}`);
const { response } = body;
if (projects.errorCodes.includes(response)) {
console.error(`Error occured attempting to ban ${id}, Error Code: ${response}`);
}
if (response === '1') {
return true;
}
}
/**
* @description Retrieves the amount of free activations for a certain service
* @param {string} service Service specified
* @param {string} country Country
* @returns {Number} Number of online nodes that can process sms activations
*/
async getCountNew(opts = {}) {
const { service, country } = opts;
const provider = projects.serviceToPID[service];
const { body } = await this._client(`http://smspva.com/priemnik.php?metod=get_count_new&country=${country}&service=${provider}&apikey=${this._key}`);
const { online } = body;
return Number(online);
}
/** @typedef {Object} SMSPVA_2FAResponse
* @property {String} code2fa The target rotating authenticated code
* @property {Number} response Indicates success or failure acquiring the 2-factor code
* @property {String} secret The same secret as provided
* @property {Number} tonew Number of seconds until a new 2-factor code will be generated
*/
/**
* @description Retrieves the 2FA code associated with the given OAUTH secret token [Useful for bypassing 2FA]
* @param {string} secret Secret for 2FA account
* @returns {SMSPVA_2FAResponse} 2FA authorization code
*/
async get2FA(secret) {
const { body } = await client(`http://smspva.com/priemnik.php?metod=get_2fa&secret=${secret}&apikey=${this._key}`);
const { response } = body;
if (response === '1') {
const { code2fa, secret } = body;
return { code2fa, secret };
}
}
}
module.exports = SMSPVAClient;