quantum-otp 0.0.0-stage → 1.0.0
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/README.md +147 -3
- package/lib/config.js +116 -0
- package/lib/controllers/index.js +16 -0
- package/lib/controllers/ql-chain.js +314 -0
- package/lib/index.js +4 -0
- package/lib/services/mail.js +85 -0
- package/lib/services/otp.js +301 -0
- package/lib/services/qrng.js +137 -0
- package/lib/services/time.js +73 -0
- package/package.json +43 -6
package/README.md
CHANGED
|
@@ -1,3 +1,147 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# quantum-otp
|
|
2
|
+
|
|
3
|
+
One-time passwords (OTPs) made from a **Quantum Random Number Generator**,
|
|
4
|
+
with no database. OTPs expire after the time you choose and can be used once.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install quantum-otp
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
import qrng from "quantum-otp"; // or: const qrng = require("quantum-otp");
|
|
16
|
+
|
|
17
|
+
qrng.configure({
|
|
18
|
+
signingSecret: "a-long-random-secret-at-least-16-characters",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create an OTP valid for 5 minutes, 6 digits
|
|
22
|
+
const { otp, otpToken, expiresAt } = await qrng.createOTP({
|
|
23
|
+
token: "<your QRNG token>", // optional
|
|
24
|
+
minutes: 5,
|
|
25
|
+
digits: 6,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Later: verify what the user typed
|
|
29
|
+
const { valid, reason, message } = await qrng.checkOTP(userTypedOtp, otpToken);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Give the `otp` to the user and keep the `otpToken` on your side (session,
|
|
33
|
+
frontend state, ...). The `otpToken` does not contain the OTP.
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Call `configure()` once when your app starts. You only need the parts you use.
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
qrng.configure({
|
|
41
|
+
// Required: used to sign otpTokens. Keep it private, and use the same
|
|
42
|
+
// value on every server that verifies OTPs.
|
|
43
|
+
signingSecret: "a-long-random-secret-at-least-16-characters",
|
|
44
|
+
|
|
45
|
+
// Optional: time zone for readable expiry times, e.g. "Asia/Dubai"
|
|
46
|
+
// (default: the server's time zone)
|
|
47
|
+
timeZone: "Asia/Dubai",
|
|
48
|
+
|
|
49
|
+
// Optional: true = throw an error instead of using local random when there
|
|
50
|
+
// is no QRNG token or the QRNG service fails (default false)
|
|
51
|
+
strict: false,
|
|
52
|
+
|
|
53
|
+
// Only needed for sendOTPEmail (any SMTP server)
|
|
54
|
+
mail: {
|
|
55
|
+
host: "smtp.gmail.com",
|
|
56
|
+
port: 587,
|
|
57
|
+
user: "you@gmail.com",
|
|
58
|
+
password: "your-app-password",
|
|
59
|
+
secure: false,
|
|
60
|
+
requireTLS: true,
|
|
61
|
+
fromEmail: "you@gmail.com",
|
|
62
|
+
fromName: "My App",
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// Only needed for sendOTPSMS (AWS SNS)
|
|
66
|
+
sms: {
|
|
67
|
+
accessKeyId: "...",
|
|
68
|
+
secretAccessKey: "...",
|
|
69
|
+
region: "ap-northeast-1",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Tip: load these values from your own config or secrets store rather than
|
|
75
|
+
writing them in your code.
|
|
76
|
+
|
|
77
|
+
## Options
|
|
78
|
+
|
|
79
|
+
For `createOTP`, `sendOTPEmail` and `sendOTPSMS`:
|
|
80
|
+
|
|
81
|
+
| Option | Default | Effect |
|
|
82
|
+
| --- | --- | --- |
|
|
83
|
+
| `token` | none | Your QRNG token, passed per call. Without it (or if the QRNG service fails) a secure local random number is used, and `source` / `message` say so |
|
|
84
|
+
| `minutes` | `5` | How long the OTP is valid (max 1440) |
|
|
85
|
+
| `digits` | `6` | OTP length, 4 to 8 |
|
|
86
|
+
| `otpRequired` | `true` | `false` = no OTP is made or sent; `checkOTP(null, otpToken)` passes with reason `otp_not_required` |
|
|
87
|
+
| `strict` | `false` | `true` = throw an error instead of using local random |
|
|
88
|
+
| `timeZone` | from `configure()` | Time zone for `expiresAtText` and the email/SMS text, e.g. `"Asia/Karachi"` |
|
|
89
|
+
| `subject` | "Your verification code" | Email subject (`sendOTPEmail` only) |
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
const skip = await qrng.createOTP({ otpRequired: false });
|
|
93
|
+
await qrng.checkOTP(null, skip.otpToken);
|
|
94
|
+
// { success: true, valid: true, reason: "otp_not_required", message: "OTP is not required. Verified successfully." }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Send by email or SMS
|
|
98
|
+
|
|
99
|
+
You get only the `otpToken` back; the OTP goes straight to the user.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
const token = "<your QRNG token>"; // optional
|
|
103
|
+
|
|
104
|
+
const byEmail = await qrng.sendOTPEmail("user@example.com", { token, minutes: 5, subject: "Your code" });
|
|
105
|
+
const bySms = await qrng.sendOTPSMS("+971500000000", { token, minutes: 5 });
|
|
106
|
+
|
|
107
|
+
const result = await qrng.checkOTP(userTypedOtp, byEmail.otpToken);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Results
|
|
111
|
+
|
|
112
|
+
Every result has `success` and a `message` you can show to the user.
|
|
113
|
+
|
|
114
|
+
Expiry is given two ways:
|
|
115
|
+
|
|
116
|
+
| Field | Example | For |
|
|
117
|
+
| --- | --- | --- |
|
|
118
|
+
| `expiresAt` | `2026-11-23T21:03:04.049Z` | code (ISO, UTC) |
|
|
119
|
+
| `expiresAtText` | `Nov 24, 2026, 01:03:04 AM GMT+4` | people (date, seconds, AM/PM, time zone) |
|
|
120
|
+
| `expiresInText` | `2 minutes` | people |
|
|
121
|
+
|
|
122
|
+
The email says: "This code expires at **Nov 24, 2026, 01:03:04 AM GMT+4** (in 2 minutes)."
|
|
123
|
+
|
|
124
|
+
`checkOTP` returns `{ success, valid, reason, message, expiresAt, expiresAtText }`, where
|
|
125
|
+
`reason` is one of:
|
|
126
|
+
|
|
127
|
+
| reason | message |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `ok` | OTP verified successfully. |
|
|
130
|
+
| `otp_not_required` | OTP is not required. Verified successfully. |
|
|
131
|
+
| `invalid_otp` | The OTP is incorrect. Please check the code and try again. |
|
|
132
|
+
| `expired` | This OTP has expired. Please request a new one. |
|
|
133
|
+
| `already_used` | This OTP has already been used. Please request a new one. |
|
|
134
|
+
| `too_many_attempts` | Too many wrong attempts. Please request a new OTP. |
|
|
135
|
+
| `invalid_token` | This verification request is not valid. Please request a new OTP. |
|
|
136
|
+
| `missing_input` | Please enter the OTP. |
|
|
137
|
+
|
|
138
|
+
A wrong OTP is never accepted. After 5 wrong tries the OTP is locked, and each
|
|
139
|
+
OTP can be used once. These checks are kept in the memory of the running
|
|
140
|
+
process.
|
|
141
|
+
|
|
142
|
+
## Old API
|
|
143
|
+
|
|
144
|
+
`createNewOTP(minutes, digits, token)`, `verifyOTP(key, otp)`,
|
|
145
|
+
`sendEmail(email, subject, minutes, digits, token)` and
|
|
146
|
+
`sendSMS(phone, minutes, digits, token)` still work as before, but only verify
|
|
147
|
+
inside the same process. Prefer `createOTP` / `checkOTP`.
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.configure = configure;
|
|
7
|
+
exports.resetConfig = resetConfig;
|
|
8
|
+
exports.getSigningSecret = getSigningSecret;
|
|
9
|
+
exports.getQrngBaseUrlSetting = getQrngBaseUrlSetting;
|
|
10
|
+
exports.getStrictSetting = getStrictSetting;
|
|
11
|
+
exports.getMailSettings = getMailSettings;
|
|
12
|
+
exports.getSmsSettings = getSmsSettings;
|
|
13
|
+
exports.getTimeZoneSetting = getTimeZoneSetting;
|
|
14
|
+
exports.getAlertEmailTo = getAlertEmailTo;
|
|
15
|
+
// Settings for the library.
|
|
16
|
+
//
|
|
17
|
+
// Set them in code with configure({...}). Anything not set in code falls back
|
|
18
|
+
// to an environment variable (handy for the REST API / command line, which
|
|
19
|
+
// read a .env file), and then to a default.
|
|
20
|
+
|
|
21
|
+
let settings = {};
|
|
22
|
+
|
|
23
|
+
function isPlainObject(value) {
|
|
24
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function merge(target, source) {
|
|
28
|
+
const out = Object.assign({}, target);
|
|
29
|
+
Object.keys(source).forEach(key => {
|
|
30
|
+
const value = source[key];
|
|
31
|
+
if (value === undefined) return;
|
|
32
|
+
out[key] = isPlainObject(value) && isPlainObject(out[key]) ? merge(out[key], value) : value;
|
|
33
|
+
});
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Configure the library. Can be called more than once; values are merged.
|
|
39
|
+
*
|
|
40
|
+
* @param {object} options
|
|
41
|
+
* @param {string} [options.signingSecret] secret used to sign otpTokens (min 16 chars)
|
|
42
|
+
* @param {string} [options.qrngBaseUrl] base URL of the QRNG API
|
|
43
|
+
* @param {boolean} [options.strict] default for the per-call `strict` option
|
|
44
|
+
* @param {object} [options.mail] { host, port, user, password, secure,
|
|
45
|
+
* requireTLS, ignoreTLS, fromEmail, fromName }
|
|
46
|
+
* @param {object} [options.sms] { accessKeyId, secretAccessKey, region }
|
|
47
|
+
* @param {string} [options.alertEmailTo] who gets the "QRNG API not working" email
|
|
48
|
+
* @param {string} [options.timeZone] time zone for readable times, e.g. "Asia/Dubai"
|
|
49
|
+
* (default: the server's time zone)
|
|
50
|
+
*/
|
|
51
|
+
function configure(options) {
|
|
52
|
+
if (options !== undefined && !isPlainObject(options)) {
|
|
53
|
+
throw new TypeError("configure() expects an object");
|
|
54
|
+
}
|
|
55
|
+
settings = merge(settings, options || {});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Forget everything set with configure() (mainly for tests). */
|
|
59
|
+
function resetConfig() {
|
|
60
|
+
settings = {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function pick(value, envName, fallback) {
|
|
64
|
+
if (value !== undefined && value !== null && value !== "") return value;
|
|
65
|
+
const env = envName ? process.env[envName] : undefined;
|
|
66
|
+
if (env !== undefined && env !== "") return env;
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function section(name) {
|
|
71
|
+
return isPlainObject(settings[name]) ? settings[name] : {};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getSigningSecret() {
|
|
75
|
+
return pick(settings.signingSecret, "OTP_SIGNING_SECRET");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getQrngBaseUrlSetting(defaultUrl) {
|
|
79
|
+
return pick(settings.qrngBaseUrl, "QRNG_BASE_URL", defaultUrl);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getStrictSetting() {
|
|
83
|
+
return pick(settings.strict, "QRNG_STRICT");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getMailSettings() {
|
|
87
|
+
const mail = section("mail");
|
|
88
|
+
return {
|
|
89
|
+
host: pick(mail.host, "MAIL_HOST", "smtp.gmail.com"),
|
|
90
|
+
port: pick(mail.port, "MAIL_PORT", 587),
|
|
91
|
+
user: pick(mail.user, "MAIL_USER"),
|
|
92
|
+
password: pick(mail.password, "MAIL_PASSWORD"),
|
|
93
|
+
secure: pick(mail.secure, "MAIL_SECURE"),
|
|
94
|
+
requireTLS: pick(mail.requireTLS, "MAIL_REQUIRE_TLS"),
|
|
95
|
+
ignoreTLS: pick(mail.ignoreTLS, "MAIL_IGNORE_TLS"),
|
|
96
|
+
fromEmail: pick(mail.fromEmail, "MAIL_DEFAULT_EMAIL"),
|
|
97
|
+
fromName: pick(mail.fromName, "MAIL_DEFAULT_NAME")
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getSmsSettings() {
|
|
102
|
+
const sms = section("sms");
|
|
103
|
+
return {
|
|
104
|
+
accessKeyId: pick(sms.accessKeyId, "AWS_ACCESS_KEY_ID"),
|
|
105
|
+
secretAccessKey: pick(sms.secretAccessKey, "AWS_SECRET_ACCESS_KEY"),
|
|
106
|
+
region: pick(sms.region, "AWS_REGION", "ap-northeast-1")
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getTimeZoneSetting() {
|
|
111
|
+
return pick(settings.timeZone, "TIME_ZONE");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function getAlertEmailTo() {
|
|
115
|
+
return pick(settings.alertEmailTo, "ALERT_EMAIL_TO");
|
|
116
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _qlChain = require("./ql-chain");
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "QLChain", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _interopRequireDefault(_qlChain).default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
4
|
+
|
|
5
|
+
var _axios = require("axios");
|
|
6
|
+
|
|
7
|
+
var _axios2 = _interopRequireDefault(_axios);
|
|
8
|
+
|
|
9
|
+
var _hexTo = require("hex-to-32");
|
|
10
|
+
|
|
11
|
+
var _hexTo2 = _interopRequireDefault(_hexTo);
|
|
12
|
+
|
|
13
|
+
var _awsSdk = require("aws-sdk");
|
|
14
|
+
|
|
15
|
+
var _awsSdk2 = _interopRequireDefault(_awsSdk);
|
|
16
|
+
|
|
17
|
+
var _crypto = require("crypto");
|
|
18
|
+
|
|
19
|
+
var _crypto2 = _interopRequireDefault(_crypto);
|
|
20
|
+
|
|
21
|
+
var _base = require("base32.js");
|
|
22
|
+
|
|
23
|
+
var _base2 = _interopRequireDefault(_base);
|
|
24
|
+
|
|
25
|
+
var _qrng = require("../services/qrng");
|
|
26
|
+
|
|
27
|
+
var _otp = require("../services/otp");
|
|
28
|
+
|
|
29
|
+
var otpService = _interopRequireWildcard(_otp);
|
|
30
|
+
|
|
31
|
+
var _config = require("../config");
|
|
32
|
+
|
|
33
|
+
var config = _interopRequireWildcard(_config);
|
|
34
|
+
|
|
35
|
+
var _mail = require("../services/mail");
|
|
36
|
+
|
|
37
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
38
|
+
|
|
39
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
|
+
|
|
41
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
42
|
+
|
|
43
|
+
let QLChain = function () {
|
|
44
|
+
function QLChain() {
|
|
45
|
+
_classCallCheck(this, QLChain);
|
|
46
|
+
|
|
47
|
+
this.key = "";
|
|
48
|
+
this.time = 0;
|
|
49
|
+
this.limit = 6;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Set the library settings in code (see README). Values are merged, so it
|
|
54
|
+
* can be called more than once. Returns this object, so calls can chain.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
_createClass(QLChain, [{
|
|
59
|
+
key: "configure",
|
|
60
|
+
value: function configure(options) {
|
|
61
|
+
config.configure(options);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ---------------------------------------------------------------------
|
|
66
|
+
// Stateless OTP (recommended). Nothing is stored in a database.
|
|
67
|
+
// ---------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create an OTP from a QRNG random number.
|
|
71
|
+
* @param {{token?: string, minutes?: number, digits?: number,
|
|
72
|
+
* otpRequired?: boolean, strict?: boolean}} [options]
|
|
73
|
+
* token = your QRNG API token (optional; without it a secure local
|
|
74
|
+
* random number is used unless strict: true)
|
|
75
|
+
* @returns {Promise<{otp, otpToken, expiresAt, expiresInSeconds, digits, source}>}
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
}, {
|
|
79
|
+
key: "createOTP",
|
|
80
|
+
value: async function createOTP(options) {
|
|
81
|
+
return otpService.createOTP(options);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Verify an OTP with the otpToken from createOTP / sendOTPEmail / sendOTPSMS.
|
|
86
|
+
* Valid only before it expires, and only once.
|
|
87
|
+
* @returns {Promise<{valid: boolean, reason: string, expiresAt?: string}>}
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
}, {
|
|
91
|
+
key: "checkOTP",
|
|
92
|
+
value: async function checkOTP(otp, otpToken) {
|
|
93
|
+
return otpService.verifyOTP(otp, otpToken);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create an OTP and email it. Returns the otpToken (not the OTP).
|
|
98
|
+
* options: { token?, minutes, digits, subject, otpRequired, strict, timeZone }
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
}, {
|
|
102
|
+
key: "sendOTPEmail",
|
|
103
|
+
value: async function sendOTPEmail(emailTo, options) {
|
|
104
|
+
const opts = options || {};
|
|
105
|
+
const created = await otpService.createOTP(opts);
|
|
106
|
+
if (!created.otpRequired) return this.withoutOtp(created);
|
|
107
|
+
if (!emailTo) throw new otpService.OtpError("email is required");
|
|
108
|
+
|
|
109
|
+
await (0, _mail.sendMail)({
|
|
110
|
+
to: emailTo,
|
|
111
|
+
subject: opts.subject || "Your verification code",
|
|
112
|
+
html: `Dear User,<br/><br/>Your verification code is: <b>${created.otp}</b><br/><br/>` + `This code expires at <b>${created.expiresAtText}</b> (in ${created.expiresInText}).<br/>`
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return this.withoutOtp(created, "OTP sent by email. " + created.message);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Result for send-email / send-sms: everything except the OTP itself.
|
|
119
|
+
|
|
120
|
+
}, {
|
|
121
|
+
key: "withoutOtp",
|
|
122
|
+
value: function withoutOtp(created, message) {
|
|
123
|
+
return {
|
|
124
|
+
success: true,
|
|
125
|
+
otpRequired: created.otpRequired,
|
|
126
|
+
otpToken: created.otpToken,
|
|
127
|
+
expiresAt: created.expiresAt,
|
|
128
|
+
expiresAtText: created.expiresAtText,
|
|
129
|
+
expiresInSeconds: created.expiresInSeconds,
|
|
130
|
+
expiresInText: created.expiresInText,
|
|
131
|
+
source: created.source,
|
|
132
|
+
message: message || created.message
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Create an OTP and send it by SMS (AWS SNS). Returns the otpToken (not the OTP).
|
|
138
|
+
* options: { token?, minutes, digits, otpRequired, strict, timeZone }
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
}, {
|
|
142
|
+
key: "sendOTPSMS",
|
|
143
|
+
value: async function sendOTPSMS(phoneNumber, options) {
|
|
144
|
+
const created = await otpService.createOTP(options || {});
|
|
145
|
+
if (!created.otpRequired) return this.withoutOtp(created);
|
|
146
|
+
if (!phoneNumber) throw new otpService.OtpError("phone is required");
|
|
147
|
+
|
|
148
|
+
const sns = await this.SMSEmitter();
|
|
149
|
+
await sns.publish({
|
|
150
|
+
Message: "Your OTP code is " + created.otp + ". It expires at " + created.expiresAtText + " (in " + created.expiresInText + ").",
|
|
151
|
+
PhoneNumber: phoneNumber
|
|
152
|
+
}).promise();
|
|
153
|
+
|
|
154
|
+
return this.withoutOtp(created, "OTP sent by SMS. " + created.message);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------------------------------------------------------------------
|
|
158
|
+
// Legacy API (kept so existing users of the package keep working).
|
|
159
|
+
// These keep the QRNG key in memory on this object, so verifyOTP only
|
|
160
|
+
// works in the same process that created the OTP. Prefer the methods above.
|
|
161
|
+
// ---------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
}, {
|
|
164
|
+
key: "CallQRNGData",
|
|
165
|
+
value: async function CallQRNGData(token) {
|
|
166
|
+
const random = await (0, _qrng.getRandomDecimal)(token);
|
|
167
|
+
return _hexTo2.default.encode(random.value.slice(0, 16).toUpperCase()).toUpperCase();
|
|
168
|
+
}
|
|
169
|
+
}, {
|
|
170
|
+
key: "totpService",
|
|
171
|
+
value: async function totpService(token = "") {
|
|
172
|
+
if (!token) {
|
|
173
|
+
return "Token should not be empty";
|
|
174
|
+
}
|
|
175
|
+
const generateNumber = await this.createNewOTP(1, 6, token);
|
|
176
|
+
return this.verifyOTP(generateNumber.key, generateNumber.otp);
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "generateTOTP",
|
|
180
|
+
value: async function generateTOTP(secret, timeWindowInMinutes, digits = 6) {
|
|
181
|
+
const timeStep = this.time;
|
|
182
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
183
|
+
const startWindow = Math.floor(currentTime / (timeWindowInMinutes * 60)) * (timeWindowInMinutes * 60);
|
|
184
|
+
const decodedSecret = _base2.default.decode(secret);
|
|
185
|
+
const hmac = _crypto2.default.createHmac("sha1", Buffer.from(decodedSecret));
|
|
186
|
+
const counter = Math.floor(startWindow / timeStep);
|
|
187
|
+
const counterBuffer = Buffer.alloc(8);
|
|
188
|
+
for (let i = 7; i >= 0; i--) {
|
|
189
|
+
counterBuffer.writeUInt8(counter >> i * 8 & 0xff, i);
|
|
190
|
+
}
|
|
191
|
+
const hash = hmac.update(counterBuffer).digest();
|
|
192
|
+
const offset = hash[hash.length - 1] & 0xf;
|
|
193
|
+
const code = ((hash[offset] & 0x7f) << 24 | (hash[offset + 1] & 0xff) << 16 | (hash[offset + 2] & 0xff) << 8 | hash[offset + 3] & 0xff) % Math.pow(10, digits);
|
|
194
|
+
return code.toString().padStart(digits, "0");
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "createNewOTP",
|
|
198
|
+
value: async function createNewOTP(time, digitLimit, token = "") {
|
|
199
|
+
if (!token) {
|
|
200
|
+
return "Token should not be empty";
|
|
201
|
+
}
|
|
202
|
+
this.key = await this.CallQRNGData(token);
|
|
203
|
+
this.time = time;
|
|
204
|
+
this.limit = digitLimit;
|
|
205
|
+
const otp = await this.generateTOTP(this.key, this.time, digitLimit);
|
|
206
|
+
return { otp, key: this.key };
|
|
207
|
+
}
|
|
208
|
+
}, {
|
|
209
|
+
key: "verifyOTP",
|
|
210
|
+
value: async function verifyOTP(secret, otpToVerify) {
|
|
211
|
+
if (!secret || !otpToVerify || !this.time) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
const generatedOTP = await this.generateTOTP(secret, this.time, this.limit);
|
|
215
|
+
return String(otpToVerify) === generatedOTP;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Uses the MAIL_* settings from .env; user/password are optional overrides.
|
|
219
|
+
|
|
220
|
+
}, {
|
|
221
|
+
key: "createEMAILService",
|
|
222
|
+
value: async function createEMAILService(user, password) {
|
|
223
|
+
return (0, _mail.createMailTransport)(user, password);
|
|
224
|
+
}
|
|
225
|
+
}, {
|
|
226
|
+
key: "sendLegacyEmail",
|
|
227
|
+
value: async function sendLegacyEmail(emailTo, subject, otp) {
|
|
228
|
+
await (0, _mail.sendMail)({
|
|
229
|
+
to: emailTo,
|
|
230
|
+
subject: subject,
|
|
231
|
+
html: `Dear User,<br/><br/> Here is the detail:<br/><br/>OTP : ${otp}<br/><br/>`
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}, {
|
|
235
|
+
key: "createMnemonics",
|
|
236
|
+
value: async function createMnemonics(emailTo, subject, time = 5, limit = 6, token = "") {
|
|
237
|
+
if (!token) {
|
|
238
|
+
return "Token should not be empty";
|
|
239
|
+
}
|
|
240
|
+
const otp = await this.createNewOTP(time, limit, token);
|
|
241
|
+
await this.sendLegacyEmail(emailTo, subject, otp.otp);
|
|
242
|
+
return otp.key;
|
|
243
|
+
}
|
|
244
|
+
}, {
|
|
245
|
+
key: "sendEmail",
|
|
246
|
+
value: async function sendEmail(emailTo, subject, time = 5, limit = 6, token = "") {
|
|
247
|
+
if (!token) {
|
|
248
|
+
return "Token should not be empty";
|
|
249
|
+
}
|
|
250
|
+
const otp = await this.createNewOTP(time, limit, token);
|
|
251
|
+
await this.sendLegacyEmail(emailTo, subject, otp.otp);
|
|
252
|
+
return otp;
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "SMSEmitter",
|
|
256
|
+
value: async function SMSEmitter() {
|
|
257
|
+
const sms = config.getSmsSettings();
|
|
258
|
+
if (!sms.accessKeyId || !sms.secretAccessKey) {
|
|
259
|
+
throw new otpService.OtpError("SMS is not configured. Call configure({ sms: { accessKeyId, secretAccessKey, region } }) before sending SMS.", 500);
|
|
260
|
+
}
|
|
261
|
+
return new _awsSdk2.default.SNS({
|
|
262
|
+
accessKeyId: sms.accessKeyId,
|
|
263
|
+
secretAccessKey: sms.secretAccessKey,
|
|
264
|
+
region: sms.region
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}, {
|
|
268
|
+
key: "sendSMS",
|
|
269
|
+
value: async function sendSMS(to_number, time = 5, limit = 6, token = "") {
|
|
270
|
+
if (!token) {
|
|
271
|
+
return "Token should not be empty";
|
|
272
|
+
}
|
|
273
|
+
const sns = await this.SMSEmitter();
|
|
274
|
+
const otp = await this.createNewOTP(time, limit, token);
|
|
275
|
+
await sns.publish({
|
|
276
|
+
Message: "Your OTP code is " + otp.otp,
|
|
277
|
+
PhoneNumber: to_number
|
|
278
|
+
}).promise();
|
|
279
|
+
return otp;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Health check for the QRNG API: true if the server answers at all
|
|
283
|
+
// (even 401 without a token), false if it cannot be reached or errors (5xx).
|
|
284
|
+
|
|
285
|
+
}, {
|
|
286
|
+
key: "tomorrowmarsAPIdata",
|
|
287
|
+
value: async function tomorrowmarsAPIdata() {
|
|
288
|
+
try {
|
|
289
|
+
await _axios2.default.get((0, _qrng.getQrngApiUrl)(), { timeout: 10000 });
|
|
290
|
+
return true;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
return Boolean(error.response && error.response.status < 500);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
key: "cronJobForTomorrowmas",
|
|
297
|
+
value: async function cronJobForTomorrowmas() {
|
|
298
|
+
const ok = await this.tomorrowmarsAPIdata();
|
|
299
|
+
const alertTo = config.getAlertEmailTo();
|
|
300
|
+
if (!ok && alertTo) {
|
|
301
|
+
await (0, _mail.sendMail)({
|
|
302
|
+
to: alertTo,
|
|
303
|
+
subject: "QRNG API not working",
|
|
304
|
+
html: `Hello,<br/><br/>The QRNG API (${(0, _qrng.getQrngApiUrl)()}) is not working.<br/><br/>Please have a look.<br/>`
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
return ok;
|
|
308
|
+
}
|
|
309
|
+
}]);
|
|
310
|
+
|
|
311
|
+
return QLChain;
|
|
312
|
+
}();
|
|
313
|
+
|
|
314
|
+
module.exports = new QLChain();
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MailError = undefined;
|
|
7
|
+
exports.getMailConfig = getMailConfig;
|
|
8
|
+
exports.createMailTransport = createMailTransport;
|
|
9
|
+
exports.getMailFrom = getMailFrom;
|
|
10
|
+
exports.sendMail = sendMail;
|
|
11
|
+
|
|
12
|
+
var _nodemailer = require("nodemailer");
|
|
13
|
+
|
|
14
|
+
var nodemailer = _interopRequireWildcard(_nodemailer);
|
|
15
|
+
|
|
16
|
+
var _config = require("../config");
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
19
|
+
|
|
20
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
|
+
|
|
22
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
23
|
+
|
|
24
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
25
|
+
|
|
26
|
+
// Mail settings: configure({ mail: {...} }), falling back to MAIL_* env vars.
|
|
27
|
+
|
|
28
|
+
function toBool(value, defaultValue) {
|
|
29
|
+
if (value === undefined || value === null || value === "") return defaultValue;
|
|
30
|
+
return value === true || String(value).trim().toLowerCase() === "true";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let MailError = exports.MailError = function (_Error) {
|
|
34
|
+
_inherits(MailError, _Error);
|
|
35
|
+
|
|
36
|
+
function MailError(message, statusCode) {
|
|
37
|
+
_classCallCheck(this, MailError);
|
|
38
|
+
|
|
39
|
+
var _this = _possibleConstructorReturn(this, (MailError.__proto__ || Object.getPrototypeOf(MailError)).call(this, message));
|
|
40
|
+
|
|
41
|
+
_this.name = "MailError";
|
|
42
|
+
_this.statusCode = statusCode || 500;
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return MailError;
|
|
47
|
+
}(Error);
|
|
48
|
+
|
|
49
|
+
function getMailConfig(user, password) {
|
|
50
|
+
const mail = (0, _config.getMailSettings)();
|
|
51
|
+
const port = Number(mail.port);
|
|
52
|
+
return {
|
|
53
|
+
host: mail.host,
|
|
54
|
+
port,
|
|
55
|
+
// true for port 465, false for 587 (STARTTLS)
|
|
56
|
+
secure: toBool(mail.secure, port === 465),
|
|
57
|
+
requireTLS: toBool(mail.requireTLS, false),
|
|
58
|
+
ignoreTLS: toBool(mail.ignoreTLS, false),
|
|
59
|
+
auth: {
|
|
60
|
+
user: user || mail.user,
|
|
61
|
+
pass: password || mail.password
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function createMailTransport(user, password) {
|
|
67
|
+
const config = getMailConfig(user, password);
|
|
68
|
+
if (!config.auth.user || !config.auth.pass) {
|
|
69
|
+
throw new MailError("Email is not configured. Call configure({ mail: { user, password, ... } }) before sending email.");
|
|
70
|
+
}
|
|
71
|
+
return nodemailer.createTransport(config);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// "TEST_APP <you@example.com>" style sender
|
|
75
|
+
function getMailFrom() {
|
|
76
|
+
const mail = (0, _config.getMailSettings)();
|
|
77
|
+
const email = mail.fromEmail || mail.user;
|
|
78
|
+
const name = mail.fromName;
|
|
79
|
+
return name ? `"${String(name).replace(/"/g, "")}" <${email}>` : email;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function sendMail(options) {
|
|
83
|
+
const transporter = createMailTransport();
|
|
84
|
+
return transporter.sendMail(Object.assign({ from: getMailFrom() }, options));
|
|
85
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MESSAGES = exports.OtpError = exports.MAX_FAILED_ATTEMPTS = exports.MAX_MINUTES = exports.MAX_DIGITS = exports.MIN_DIGITS = exports.DEFAULT_DIGITS = exports.DEFAULT_MINUTES = undefined;
|
|
7
|
+
exports.otpFromRandom = otpFromRandom;
|
|
8
|
+
exports.createOTP = createOTP;
|
|
9
|
+
exports.verifyOTP = verifyOTP;
|
|
10
|
+
|
|
11
|
+
var _crypto = require("crypto");
|
|
12
|
+
|
|
13
|
+
var _crypto2 = _interopRequireDefault(_crypto);
|
|
14
|
+
|
|
15
|
+
var _qrng = require("./qrng");
|
|
16
|
+
|
|
17
|
+
var _config = require("../config");
|
|
18
|
+
|
|
19
|
+
var _time = require("./time");
|
|
20
|
+
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
|
|
23
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
24
|
+
|
|
25
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
26
|
+
|
|
27
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Stateless OTP: nothing is stored in a database.
|
|
31
|
+
*
|
|
32
|
+
* createOTP():
|
|
33
|
+
* 1. Gets a random number from the QRNG API (if a token is given), or a
|
|
34
|
+
* secure local random number (no token / QRNG failed, unless strict).
|
|
35
|
+
* 2. Turns it into an N-digit OTP.
|
|
36
|
+
* 3. Builds an `otpToken` = payload (expiry time, digits, nonce) + an HMAC
|
|
37
|
+
* signature of (payload + OTP) made with OTP_SIGNING_SECRET.
|
|
38
|
+
* The OTP is sent to the user (email/SMS); the otpToken is kept by the
|
|
39
|
+
* caller (your app / frontend). The otpToken does NOT contain the OTP and
|
|
40
|
+
* the OTP cannot be worked out from it without OTP_SIGNING_SECRET.
|
|
41
|
+
*
|
|
42
|
+
* verifyOTP(otp, otpToken):
|
|
43
|
+
* Re-computes the signature with the OTP the user typed. If it matches and
|
|
44
|
+
* the expiry time has not passed, the OTP is valid.
|
|
45
|
+
*
|
|
46
|
+
* otpRequired: false
|
|
47
|
+
* No OTP is made. The otpToken is still signed, and verifying it passes
|
|
48
|
+
* automatically (until it expires). Lets the developer switch OTP off per
|
|
49
|
+
* request without changing the rest of their flow.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const DEFAULT_MINUTES = exports.DEFAULT_MINUTES = 5;
|
|
53
|
+
const DEFAULT_DIGITS = exports.DEFAULT_DIGITS = 6;
|
|
54
|
+
const MIN_DIGITS = exports.MIN_DIGITS = 4;
|
|
55
|
+
const MAX_DIGITS = exports.MAX_DIGITS = 8;
|
|
56
|
+
const MAX_MINUTES = exports.MAX_MINUTES = 1440; // 24 hours
|
|
57
|
+
const MAX_FAILED_ATTEMPTS = exports.MAX_FAILED_ATTEMPTS = 5;
|
|
58
|
+
|
|
59
|
+
let OtpError = exports.OtpError = function (_Error) {
|
|
60
|
+
_inherits(OtpError, _Error);
|
|
61
|
+
|
|
62
|
+
function OtpError(message, statusCode) {
|
|
63
|
+
_classCallCheck(this, OtpError);
|
|
64
|
+
|
|
65
|
+
var _this = _possibleConstructorReturn(this, (OtpError.__proto__ || Object.getPrototypeOf(OtpError)).call(this, message));
|
|
66
|
+
|
|
67
|
+
_this.name = "OtpError";
|
|
68
|
+
_this.statusCode = statusCode || 400;
|
|
69
|
+
return _this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return OtpError;
|
|
73
|
+
}(Error);
|
|
74
|
+
|
|
75
|
+
function getSigningSecret() {
|
|
76
|
+
const secret = (0, _config.getSigningSecret)();
|
|
77
|
+
if (!secret || String(secret).length < 16) {
|
|
78
|
+
throw new OtpError("signingSecret is missing or too short (min 16 characters). Call configure({ signingSecret: \"...\" }).", 500);
|
|
79
|
+
}
|
|
80
|
+
return secret;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function toBase64Url(buffer) {
|
|
84
|
+
return Buffer.from(buffer).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function fromBase64Url(text) {
|
|
88
|
+
let base64 = String(text).replace(/-/g, "+").replace(/_/g, "/");
|
|
89
|
+
while (base64.length % 4) base64 += "=";
|
|
90
|
+
return Buffer.from(base64, "base64");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function sign(payloadPart, otp) {
|
|
94
|
+
return toBase64Url(_crypto2.default.createHmac("sha256", getSigningSecret()).update(payloadPart + "." + otp).digest());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Turn the QRNG random number into an OTP of `digits` digits.
|
|
99
|
+
* The number is run through HMAC-SHA256 so every digit is evenly spread,
|
|
100
|
+
* then 48 bits are taken (RFC 4226 style dynamic truncation).
|
|
101
|
+
*/
|
|
102
|
+
function otpFromRandom(randomDecimal, digits) {
|
|
103
|
+
const hash = _crypto2.default.createHmac("sha256", String(randomDecimal)).update("qrng-otp").digest();
|
|
104
|
+
const offset = hash[hash.length - 1] & 0xf; // 0..15, +6 bytes fits in 32
|
|
105
|
+
const number = hash.readUIntBE(offset, 6);
|
|
106
|
+
return String(number % Math.pow(10, digits)).padStart(digits, "0");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function readOptions(options) {
|
|
110
|
+
const opts = options || {};
|
|
111
|
+
const minutes = opts.minutes === undefined || opts.minutes === null || opts.minutes === "" ? DEFAULT_MINUTES : Number(opts.minutes);
|
|
112
|
+
const digits = opts.digits === undefined || opts.digits === null || opts.digits === "" ? DEFAULT_DIGITS : Number(opts.digits);
|
|
113
|
+
|
|
114
|
+
if (!isFinite(minutes) || minutes <= 0 || minutes > MAX_MINUTES) {
|
|
115
|
+
throw new OtpError("minutes must be a number greater than 0 and at most " + MAX_MINUTES);
|
|
116
|
+
}
|
|
117
|
+
if (!Number.isInteger(digits) || digits < MIN_DIGITS || digits > MAX_DIGITS) {
|
|
118
|
+
throw new OtpError("digits must be a whole number from " + MIN_DIGITS + " to " + MAX_DIGITS);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
minutes,
|
|
122
|
+
digits,
|
|
123
|
+
token: typeof opts.token === "string" ? opts.token.trim() : "",
|
|
124
|
+
strict: opts.strict,
|
|
125
|
+
timeZone: opts.timeZone,
|
|
126
|
+
// otpRequired: false -> no OTP is made; verification passes automatically.
|
|
127
|
+
otpRequired: !isFalse(opts.otpRequired)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isFalse(value) {
|
|
132
|
+
return value === false || String(value).trim().toLowerCase() === "false";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function buildToken(payload, otp) {
|
|
136
|
+
const payloadPart = toBase64Url(JSON.stringify(payload));
|
|
137
|
+
return payloadPart + "." + sign(payloadPart, otp);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Create a new OTP.
|
|
142
|
+
*
|
|
143
|
+
* @param {{token?: string, minutes?: number, digits?: number,
|
|
144
|
+
* otpRequired?: boolean, strict?: boolean, timeZone?: string}} [options]
|
|
145
|
+
* - timeZone: for expiresAtText, e.g. "Asia/Dubai" (default from
|
|
146
|
+
* configure({ timeZone }) or the server's time zone).
|
|
147
|
+
* - token: QRNG API token (optional). Without it a secure local random
|
|
148
|
+
* number is used (unless strict).
|
|
149
|
+
* - otpRequired: false -> no OTP is created and verification of the
|
|
150
|
+
* returned otpToken always passes (until it expires).
|
|
151
|
+
* - strict: true -> errors instead of falling back to local random.
|
|
152
|
+
* @returns {Promise<{success, otpRequired, otp, otpToken, expiresAt,
|
|
153
|
+
* expiresAtText, expiresInSeconds, expiresInText, digits, source, message}>}
|
|
154
|
+
*/
|
|
155
|
+
async function createOTP(options) {
|
|
156
|
+
const opts = readOptions(options);
|
|
157
|
+
getSigningSecret(); // fail early, before calling the QRNG API
|
|
158
|
+
|
|
159
|
+
const now = Date.now();
|
|
160
|
+
const expiresAtMs = now + Math.round(opts.minutes * 60 * 1000);
|
|
161
|
+
const common = {
|
|
162
|
+
expiresAt: new Date(expiresAtMs).toISOString(),
|
|
163
|
+
// Readable, e.g. "Nov 24, 2026, 01:03:04 AM GMT+4"
|
|
164
|
+
expiresAtText: (0, _time.formatDateTime)(expiresAtMs, opts.timeZone),
|
|
165
|
+
expiresInSeconds: Math.round((expiresAtMs - now) / 1000),
|
|
166
|
+
// Readable, e.g. "2 minutes"
|
|
167
|
+
expiresInText: (0, _time.formatDuration)((expiresAtMs - now) / 1000)
|
|
168
|
+
};
|
|
169
|
+
const nonce = toBase64Url(_crypto2.default.randomBytes(9));
|
|
170
|
+
|
|
171
|
+
if (!opts.otpRequired) {
|
|
172
|
+
// r: 0 marks "OTP not required"; it is inside the signed payload, so it
|
|
173
|
+
// cannot be added to a normal otpToken by someone else.
|
|
174
|
+
const otpToken = buildToken({ v: 1, iat: now, exp: expiresAtMs, d: 0, r: 0, n: nonce }, "");
|
|
175
|
+
return Object.assign({
|
|
176
|
+
success: true,
|
|
177
|
+
otpRequired: false,
|
|
178
|
+
otp: null,
|
|
179
|
+
otpToken
|
|
180
|
+
}, common, {
|
|
181
|
+
digits: 0,
|
|
182
|
+
source: "none",
|
|
183
|
+
message: "OTP is not required for this request. Verification will pass automatically."
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const random = await (0, _qrng.getRandomDecimal)(opts.token, { strict: opts.strict });
|
|
188
|
+
const otp = otpFromRandom(random.value, opts.digits);
|
|
189
|
+
const otpToken = buildToken({ v: 1, iat: now, exp: expiresAtMs, d: opts.digits, n: nonce }, otp);
|
|
190
|
+
|
|
191
|
+
return Object.assign({
|
|
192
|
+
success: true,
|
|
193
|
+
otpRequired: true,
|
|
194
|
+
otp,
|
|
195
|
+
otpToken
|
|
196
|
+
}, common, {
|
|
197
|
+
digits: opts.digits,
|
|
198
|
+
source: random.source,
|
|
199
|
+
message: "OTP created successfully. " + random.message
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// In-memory only (no database): blocks reusing an OTP and limits wrong
|
|
204
|
+
// guesses while this process is running. Entries are removed once the OTP
|
|
205
|
+
// has expired. Resets when the process restarts.
|
|
206
|
+
const usedTokens = new Map(); // otpToken -> expiry ms
|
|
207
|
+
const failedAttempts = new Map(); // otpToken -> { count, exp }
|
|
208
|
+
|
|
209
|
+
function cleanUp(now) {
|
|
210
|
+
usedTokens.forEach((exp, key) => {
|
|
211
|
+
if (exp < now) usedTokens.delete(key);
|
|
212
|
+
});
|
|
213
|
+
failedAttempts.forEach((entry, key) => {
|
|
214
|
+
if (entry.exp < now) failedAttempts.delete(key);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const MESSAGES = exports.MESSAGES = {
|
|
219
|
+
ok: "OTP verified successfully.",
|
|
220
|
+
otp_not_required: "OTP is not required. Verified successfully.",
|
|
221
|
+
expired: "This OTP has expired. Please request a new one.",
|
|
222
|
+
invalid_otp: "The OTP is incorrect. Please check the code and try again.",
|
|
223
|
+
invalid_token: "This verification request is not valid. Please request a new OTP.",
|
|
224
|
+
already_used: "This OTP has already been used. Please request a new one.",
|
|
225
|
+
too_many_attempts: "Too many wrong attempts. Please request a new OTP.",
|
|
226
|
+
missing_input: "Please enter the OTP."
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
function result(valid, reason, extra) {
|
|
230
|
+
return Object.assign({ success: valid, valid, reason, message: MESSAGES[reason] }, extra || {});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function signatureMatches(payloadPart, otpText, signaturePart) {
|
|
234
|
+
const expected = fromBase64Url(sign(payloadPart, otpText));
|
|
235
|
+
const given = fromBase64Url(signaturePart);
|
|
236
|
+
return expected.length === given.length && _crypto2.default.timingSafeEqual(expected, given);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Verify an OTP against the otpToken returned by createOTP.
|
|
241
|
+
* Works only until the OTP's expiry time; each OTP can be used once.
|
|
242
|
+
*
|
|
243
|
+
* @returns {{success: boolean, valid: boolean, reason: string,
|
|
244
|
+
* message: string, expiresAt?: string, expiresAtText?: string}}
|
|
245
|
+
* reason is one of: "ok", "otp_not_required", "expired", "invalid_otp",
|
|
246
|
+
* "invalid_token", "already_used", "too_many_attempts", "missing_input".
|
|
247
|
+
*/
|
|
248
|
+
function verifyOTP(otp, otpToken) {
|
|
249
|
+
if (!otpToken) return result(false, "invalid_token");
|
|
250
|
+
|
|
251
|
+
const parts = String(otpToken).split(".");
|
|
252
|
+
if (parts.length !== 2) return result(false, "invalid_token");
|
|
253
|
+
|
|
254
|
+
let payload;
|
|
255
|
+
try {
|
|
256
|
+
payload = JSON.parse(fromBase64Url(parts[0]).toString("utf8"));
|
|
257
|
+
} catch (e) {
|
|
258
|
+
return result(false, "invalid_token");
|
|
259
|
+
}
|
|
260
|
+
if (!payload || typeof payload.exp !== "number" || typeof payload.d !== "number") {
|
|
261
|
+
return result(false, "invalid_token");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const now = Date.now();
|
|
265
|
+
cleanUp(now);
|
|
266
|
+
const expiresAt = new Date(payload.exp).toISOString();
|
|
267
|
+
const expiresAtText = (0, _time.formatDateTime)(payload.exp);
|
|
268
|
+
|
|
269
|
+
if (now > payload.exp) return result(false, "expired", { expiresAt, expiresAtText });
|
|
270
|
+
|
|
271
|
+
// Token created with otpRequired: false -> passes without an OTP.
|
|
272
|
+
if (payload.r === 0) {
|
|
273
|
+
return signatureMatches(parts[0], "", parts[1]) ? result(true, "otp_not_required", { expiresAt, expiresAtText }) : result(false, "invalid_token");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (otp === undefined || otp === null || String(otp).trim() === "") {
|
|
277
|
+
return result(false, "missing_input", { expiresAt, expiresAtText });
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const attempts = failedAttempts.get(otpToken);
|
|
281
|
+
if (attempts && attempts.count >= MAX_FAILED_ATTEMPTS) {
|
|
282
|
+
return result(false, "too_many_attempts", { expiresAt, expiresAtText });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const otpText = String(otp).trim();
|
|
286
|
+
const matches = otpText.length === payload.d && /^[0-9]+$/.test(otpText) && signatureMatches(parts[0], otpText, parts[1]);
|
|
287
|
+
|
|
288
|
+
if (!matches) {
|
|
289
|
+
failedAttempts.set(otpToken, {
|
|
290
|
+
count: (attempts ? attempts.count : 0) + 1,
|
|
291
|
+
exp: payload.exp
|
|
292
|
+
});
|
|
293
|
+
return result(false, "invalid_otp", { expiresAt, expiresAtText });
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (usedTokens.has(otpToken)) return result(false, "already_used", { expiresAt, expiresAtText });
|
|
297
|
+
usedTokens.set(otpToken, payload.exp);
|
|
298
|
+
failedAttempts.delete(otpToken);
|
|
299
|
+
|
|
300
|
+
return result(true, "ok", { expiresAt, expiresAtText });
|
|
301
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.QrngError = exports.QRNG_DECIMAL_PATH = undefined;
|
|
7
|
+
exports.getQrngBaseUrl = getQrngBaseUrl;
|
|
8
|
+
exports.getQrngApiUrl = getQrngApiUrl;
|
|
9
|
+
exports.isStrict = isStrict;
|
|
10
|
+
exports.getRandomDecimal = getRandomDecimal;
|
|
11
|
+
|
|
12
|
+
var _axios = require("axios");
|
|
13
|
+
|
|
14
|
+
var _axios2 = _interopRequireDefault(_axios);
|
|
15
|
+
|
|
16
|
+
var _crypto = require("crypto");
|
|
17
|
+
|
|
18
|
+
var _crypto2 = _interopRequireDefault(_crypto);
|
|
19
|
+
|
|
20
|
+
var _config = require("../config");
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
+
|
|
26
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
27
|
+
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
29
|
+
|
|
30
|
+
// Only the base URL is configurable (configure({ qrngBaseUrl }) or
|
|
31
|
+
// QRNG_BASE_URL); the endpoint path is added here when the call is made.
|
|
32
|
+
const DEFAULT_QRNG_BASE_URL = "https://qrng.infinialabs.ai";
|
|
33
|
+
const QRNG_DECIMAL_PATH = exports.QRNG_DECIMAL_PATH = "/api/getQrngDecimal/";
|
|
34
|
+
|
|
35
|
+
function getQrngBaseUrl() {
|
|
36
|
+
return String((0, _config.getQrngBaseUrlSetting)(DEFAULT_QRNG_BASE_URL)).replace(/\/+$/, "");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getQrngApiUrl() {
|
|
40
|
+
return getQrngBaseUrl() + QRNG_DECIMAL_PATH;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let QrngError = exports.QrngError = function (_Error) {
|
|
44
|
+
_inherits(QrngError, _Error);
|
|
45
|
+
|
|
46
|
+
function QrngError(message, statusCode) {
|
|
47
|
+
_classCallCheck(this, QrngError);
|
|
48
|
+
|
|
49
|
+
var _this = _possibleConstructorReturn(this, (QrngError.__proto__ || Object.getPrototypeOf(QrngError)).call(this, message));
|
|
50
|
+
|
|
51
|
+
_this.name = "QrngError";
|
|
52
|
+
_this.statusCode = statusCode || 502;
|
|
53
|
+
return _this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return QrngError;
|
|
57
|
+
}(Error);
|
|
58
|
+
|
|
59
|
+
// Secure local random number (Node crypto, not quantum). Used when no QRNG
|
|
60
|
+
// token is given, or when the QRNG API fails, unless strict mode is on.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function localRandomDecimal() {
|
|
64
|
+
return BigInt("0x" + _crypto2.default.randomBytes(16).toString("hex")).toString();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isTrue(value) {
|
|
68
|
+
return value === true || String(value).trim().toLowerCase() === "true";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Strict mode: if true, a missing token or a QRNG failure is an error.
|
|
73
|
+
* If false (default), a secure local random number is used instead and the
|
|
74
|
+
* result says so in `message`. Per call: { strict }; default from
|
|
75
|
+
* configure({ strict }) or QRNG_STRICT.
|
|
76
|
+
*/
|
|
77
|
+
function isStrict(strictOption) {
|
|
78
|
+
if (strictOption !== undefined && strictOption !== null && strictOption !== "") {
|
|
79
|
+
return isTrue(strictOption);
|
|
80
|
+
}
|
|
81
|
+
const value = (0, _config.getStrictSetting)();
|
|
82
|
+
return value === undefined ? false : isTrue(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get one random number: from the QRNG API when a token is given, otherwise
|
|
87
|
+
* (or if the QRNG API fails) from the secure local generator.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} [token] QRNG API token, passed by the caller (never from env)
|
|
90
|
+
* @param {{strict?: boolean}} [options]
|
|
91
|
+
* @returns {Promise<{value: string, source: "qrng" | "local", message: string}>}
|
|
92
|
+
*/
|
|
93
|
+
async function getRandomDecimal(token, options) {
|
|
94
|
+
const strict = isStrict(options && options.strict);
|
|
95
|
+
const bearer = typeof token === "string" ? token.trim() : "";
|
|
96
|
+
|
|
97
|
+
if (!bearer) {
|
|
98
|
+
if (strict) {
|
|
99
|
+
throw new QrngError("QRNG token is required in strict mode. Pass it as an argument: { token: \"<QRNG token>\" }.", 400);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
value: localRandomDecimal(),
|
|
103
|
+
source: "local",
|
|
104
|
+
message: "No QRNG token given, so a secure local random number was used."
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const response = await _axios2.default.post(getQrngApiUrl(), {}, {
|
|
110
|
+
headers: { Authorization: `Bearer ${bearer}` },
|
|
111
|
+
timeout: 10000
|
|
112
|
+
});
|
|
113
|
+
const value = response.data && response.data.data;
|
|
114
|
+
if (value === undefined || value === null || value === "") {
|
|
115
|
+
throw new Error("QRNG API returned no data");
|
|
116
|
+
}
|
|
117
|
+
// Make sure it is a whole number, then normalise it to a decimal string.
|
|
118
|
+
return {
|
|
119
|
+
value: BigInt(value).toString(),
|
|
120
|
+
source: "qrng",
|
|
121
|
+
message: "Quantum random number used."
|
|
122
|
+
};
|
|
123
|
+
} catch (error) {
|
|
124
|
+
const status = error.response && error.response.status;
|
|
125
|
+
const rejected = status === 401 || status === 403;
|
|
126
|
+
const reason = rejected ? "the QRNG API rejected the token (HTTP " + status + ")" : "the QRNG API could not be used (" + error.message + ")";
|
|
127
|
+
|
|
128
|
+
if (strict) {
|
|
129
|
+
throw new QrngError(reason.charAt(0).toUpperCase() + reason.slice(1), rejected ? 401 : 502);
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
value: localRandomDecimal(),
|
|
133
|
+
source: "local",
|
|
134
|
+
message: "QRNG was not used because " + reason + ", so a secure local random number was used."
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isValidTimeZone = isValidTimeZone;
|
|
7
|
+
exports.resolveTimeZone = resolveTimeZone;
|
|
8
|
+
exports.formatDateTime = formatDateTime;
|
|
9
|
+
exports.formatDuration = formatDuration;
|
|
10
|
+
|
|
11
|
+
var _config = require("../config");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Check a time zone name such as "Asia/Dubai", "Asia/Karachi" or "UTC".
|
|
15
|
+
* Returns true if this Node.js knows it.
|
|
16
|
+
*/
|
|
17
|
+
function isValidTimeZone(timeZone) {
|
|
18
|
+
if (!timeZone) return false;
|
|
19
|
+
try {
|
|
20
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format(new Date());
|
|
21
|
+
return true;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The time zone to use: the per-call value, else configure({ timeZone }) /
|
|
29
|
+
* TIME_ZONE, else the server's own time zone. Unknown names are ignored.
|
|
30
|
+
*/
|
|
31
|
+
function resolveTimeZone(timeZone) {
|
|
32
|
+
if (isValidTimeZone(timeZone)) return timeZone;
|
|
33
|
+
const configured = (0, _config.getTimeZoneSetting)();
|
|
34
|
+
if (isValidTimeZone(configured)) return configured;
|
|
35
|
+
return undefined; // server local time
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Readable date and time with seconds and AM/PM, e.g.
|
|
40
|
+
* "Nov 24, 2026, 01:03:04 AM GMT+4".
|
|
41
|
+
*/
|
|
42
|
+
function formatDateTime(date, timeZone) {
|
|
43
|
+
const options = {
|
|
44
|
+
year: "numeric",
|
|
45
|
+
month: "short",
|
|
46
|
+
day: "2-digit",
|
|
47
|
+
hour: "2-digit",
|
|
48
|
+
minute: "2-digit",
|
|
49
|
+
second: "2-digit",
|
|
50
|
+
hour12: true,
|
|
51
|
+
timeZoneName: "short"
|
|
52
|
+
};
|
|
53
|
+
const zone = resolveTimeZone(timeZone);
|
|
54
|
+
if (zone) options.timeZone = zone;
|
|
55
|
+
return new Intl.DateTimeFormat("en-US", options).format(new Date(date));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function plural(count, word) {
|
|
59
|
+
return count + " " + word + (count === 1 ? "" : "s");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** "2 minutes", "1 minute 30 seconds", "45 seconds", "1 hour 5 minutes" */
|
|
63
|
+
function formatDuration(totalSeconds) {
|
|
64
|
+
const seconds = Math.max(0, Math.round(totalSeconds));
|
|
65
|
+
const hours = Math.floor(seconds / 3600);
|
|
66
|
+
const minutes = Math.floor(seconds % 3600 / 60);
|
|
67
|
+
const rest = seconds % 60;
|
|
68
|
+
const parts = [];
|
|
69
|
+
if (hours) parts.push(plural(hours, "hour"));
|
|
70
|
+
if (minutes) parts.push(plural(minutes, "minute"));
|
|
71
|
+
if (rest || !parts.length) parts.push(plural(rest, "second"));
|
|
72
|
+
return parts.join(" ");
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "quantum-otp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "quantum-otp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Quantum random (QRNG) one-time passwords for Node.js: create, email/SMS and verify OTPs without a database.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"otp",
|
|
12
|
+
"quantum",
|
|
13
|
+
"qrng",
|
|
14
|
+
"quantum-otp",
|
|
15
|
+
"random",
|
|
16
|
+
"one-time-password",
|
|
17
|
+
"2fa",
|
|
18
|
+
"verification",
|
|
19
|
+
"email-otp",
|
|
20
|
+
"sms-otp",
|
|
21
|
+
"stateless"
|
|
22
|
+
],
|
|
23
|
+
"author": "Saqib Altaf",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/Quantlase/QRNG-TOTP.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/Quantlase/QRNG-TOTP/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Quantlase/QRNG-TOTP#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=12"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"aws-sdk": "^2.1309.0",
|
|
38
|
+
"axios": "^1.3.2",
|
|
39
|
+
"base32.js": "^0.1.0",
|
|
40
|
+
"hex-to-32": "^2.0.0",
|
|
41
|
+
"nodemailer": "^6.9.1"
|
|
42
|
+
}
|
|
43
|
+
}
|