irismail 0.1.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 +158 -0
- package/dist/chunk-FTNSOYOW.mjs +223 -0
- package/dist/chunk-QZ7TP4HQ.mjs +7 -0
- package/dist/chunk-XGASTZZ6.mjs +180 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +446 -0
- package/dist/index.mjs +31 -0
- package/dist/react/index.d.mts +60 -0
- package/dist/react/index.d.ts +60 -0
- package/dist/react/index.js +261 -0
- package/dist/react/index.mjs +15 -0
- package/dist/server/index.d.mts +110 -0
- package/dist/server/index.d.ts +110 -0
- package/dist/server/index.js +218 -0
- package/dist/server/index.mjs +15 -0
- package/package.json +60 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react/index.ts
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
InputOTP: () => InputOTP,
|
|
34
|
+
InputOTPGroup: () => InputOTPGroup,
|
|
35
|
+
InputOTPSeparator: () => InputOTPSeparator,
|
|
36
|
+
InputOTPSlot: () => InputOTPSlot,
|
|
37
|
+
useOTP: () => useOTP
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(react_exports);
|
|
40
|
+
|
|
41
|
+
// src/react/components/input-otp.tsx
|
|
42
|
+
var React = __toESM(require("react"));
|
|
43
|
+
var import_input_otp = require("input-otp");
|
|
44
|
+
|
|
45
|
+
// src/utils/constants.ts
|
|
46
|
+
var import_clsx = require("clsx");
|
|
47
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
48
|
+
function cn(...inputs) {
|
|
49
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
50
|
+
}
|
|
51
|
+
var OTP_DEFAULTS = {
|
|
52
|
+
LENGTH: 6,
|
|
53
|
+
EXPIRY_MINUTES: 5,
|
|
54
|
+
RESEND_COOLDOWN_SECONDS: 120,
|
|
55
|
+
// 2 minutes
|
|
56
|
+
MAX_ATTEMPTS: 5,
|
|
57
|
+
RATE_LIMIT_RESET_HOURS: 1
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/react/components/input-otp.tsx
|
|
61
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
62
|
+
var Dot = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
63
|
+
"svg",
|
|
64
|
+
{
|
|
65
|
+
width: "15",
|
|
66
|
+
height: "15",
|
|
67
|
+
viewBox: "0 0 15 15",
|
|
68
|
+
fill: "none",
|
|
69
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
70
|
+
className: "h-4 w-4",
|
|
71
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
+
"path",
|
|
73
|
+
{
|
|
74
|
+
d: "M7.5 7.5C7.5 8.32843 6.82843 9 6 9C5.17157 9 4.5 8.32843 4.5 7.5C4.5 6.67157 5.17157 6 6 6C6.82843 6 7.5 6.67157 7.5 7.5Z",
|
|
75
|
+
fill: "currentColor",
|
|
76
|
+
fillRule: "evenodd",
|
|
77
|
+
clipRule: "evenodd"
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
var InputOTP = React.forwardRef(
|
|
83
|
+
({ className, containerClassName, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
84
|
+
import_input_otp.OTPInput,
|
|
85
|
+
{
|
|
86
|
+
ref,
|
|
87
|
+
containerClassName: cn("flex items-center gap-2 has-[:disabled]:opacity-50", containerClassName),
|
|
88
|
+
className: cn("disabled:cursor-not-allowed", className),
|
|
89
|
+
...props
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
InputOTP.displayName = "InputOTP";
|
|
94
|
+
var InputOTPGroup = React.forwardRef(
|
|
95
|
+
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className: cn("flex items-center", className), ...props })
|
|
96
|
+
);
|
|
97
|
+
InputOTPGroup.displayName = "InputOTPGroup";
|
|
98
|
+
var InputOTPSlot = React.forwardRef(({ index, className, ...props }, ref) => {
|
|
99
|
+
const inputOTPContext = React.useContext(import_input_otp.OTPInputContext);
|
|
100
|
+
const { char, hasFakeCaret, isActive } = inputOTPContext.slots[index];
|
|
101
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
102
|
+
"div",
|
|
103
|
+
{
|
|
104
|
+
ref,
|
|
105
|
+
className: cn(
|
|
106
|
+
"relative flex h-10 w-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",
|
|
107
|
+
isActive && "z-10 ring-2 ring-ring ring-offset-background",
|
|
108
|
+
className
|
|
109
|
+
),
|
|
110
|
+
...props,
|
|
111
|
+
children: [
|
|
112
|
+
char,
|
|
113
|
+
hasFakeCaret && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pointer-events-none absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "h-4 w-px animate-caret-blink bg-foreground duration-1000" }) })
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
InputOTPSlot.displayName = "InputOTPSlot";
|
|
119
|
+
var InputOTPSeparator = React.forwardRef(
|
|
120
|
+
({ ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, role: "separator", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dot, {}) })
|
|
121
|
+
);
|
|
122
|
+
InputOTPSeparator.displayName = "InputOTPSeparator";
|
|
123
|
+
|
|
124
|
+
// src/react/hooks/use-otp.ts
|
|
125
|
+
var import_react = require("react");
|
|
126
|
+
function useOTP({ email, onRateLimit }) {
|
|
127
|
+
const [otpTimeLeft, setOtpTimeLeft] = (0, import_react.useState)(OTP_DEFAULTS.EXPIRY_MINUTES * 60);
|
|
128
|
+
const [resendTimeLeft, setResendTimeLeft] = (0, import_react.useState)(0);
|
|
129
|
+
const [attemptsLeft, setAttemptsLeft] = (0, import_react.useState)(OTP_DEFAULTS.MAX_ATTEMPTS);
|
|
130
|
+
const [isRateLimited, setIsRateLimited] = (0, import_react.useState)(false);
|
|
131
|
+
const [rateLimitResetTime, setRateLimitResetTime] = (0, import_react.useState)(null);
|
|
132
|
+
const getStorageKey = (prefix) => `${prefix}_${email}`;
|
|
133
|
+
const getStoredData = (key) => {
|
|
134
|
+
if (typeof window === "undefined") return null;
|
|
135
|
+
const data = sessionStorage.getItem(key);
|
|
136
|
+
return data ? JSON.parse(data) : null;
|
|
137
|
+
};
|
|
138
|
+
const setStoredData = (key, data) => {
|
|
139
|
+
if (typeof window !== "undefined") {
|
|
140
|
+
sessionStorage.setItem(key, JSON.stringify(data));
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const removeStoredData = (key) => {
|
|
144
|
+
if (typeof window !== "undefined") {
|
|
145
|
+
sessionStorage.removeItem(key);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const checkRateLimit = () => {
|
|
149
|
+
const key = getStorageKey("rate_limit");
|
|
150
|
+
const data = getStoredData(key);
|
|
151
|
+
if (!data) {
|
|
152
|
+
setAttemptsLeft(OTP_DEFAULTS.MAX_ATTEMPTS);
|
|
153
|
+
setIsRateLimited(false);
|
|
154
|
+
return { limited: false, attemptsLeft: OTP_DEFAULTS.MAX_ATTEMPTS };
|
|
155
|
+
}
|
|
156
|
+
const currentTime = Date.now();
|
|
157
|
+
const resetTime = OTP_DEFAULTS.RATE_LIMIT_RESET_HOURS * 60 * 60 * 1e3;
|
|
158
|
+
if (currentTime - data.firstAttemptTime > resetTime) {
|
|
159
|
+
removeStoredData(key);
|
|
160
|
+
setAttemptsLeft(OTP_DEFAULTS.MAX_ATTEMPTS);
|
|
161
|
+
setIsRateLimited(false);
|
|
162
|
+
return { limited: false, attemptsLeft: OTP_DEFAULTS.MAX_ATTEMPTS };
|
|
163
|
+
}
|
|
164
|
+
const attempts = OTP_DEFAULTS.MAX_ATTEMPTS - data.attempts;
|
|
165
|
+
const limited = data.attempts >= OTP_DEFAULTS.MAX_ATTEMPTS;
|
|
166
|
+
const limitResetTime = data.firstAttemptTime + resetTime;
|
|
167
|
+
setAttemptsLeft(Math.max(0, attempts));
|
|
168
|
+
setIsRateLimited(limited);
|
|
169
|
+
setRateLimitResetTime(limited ? limitResetTime : null);
|
|
170
|
+
if (limited && onRateLimit) {
|
|
171
|
+
onRateLimit(limitResetTime);
|
|
172
|
+
}
|
|
173
|
+
return { limited, attemptsLeft: Math.max(0, attempts), resetTime: limited ? limitResetTime : void 0 };
|
|
174
|
+
};
|
|
175
|
+
const updateRateLimit = () => {
|
|
176
|
+
const key = getStorageKey("rate_limit");
|
|
177
|
+
const data = getStoredData(key);
|
|
178
|
+
const currentTime = Date.now();
|
|
179
|
+
let newData;
|
|
180
|
+
if (!data) {
|
|
181
|
+
newData = {
|
|
182
|
+
attempts: 1,
|
|
183
|
+
firstAttemptTime: currentTime,
|
|
184
|
+
lastAttemptTime: currentTime
|
|
185
|
+
};
|
|
186
|
+
} else {
|
|
187
|
+
const resetTime = OTP_DEFAULTS.RATE_LIMIT_RESET_HOURS * 60 * 60 * 1e3;
|
|
188
|
+
if (currentTime - data.firstAttemptTime > resetTime) {
|
|
189
|
+
newData = {
|
|
190
|
+
attempts: 1,
|
|
191
|
+
firstAttemptTime: currentTime,
|
|
192
|
+
lastAttemptTime: currentTime
|
|
193
|
+
};
|
|
194
|
+
} else {
|
|
195
|
+
newData = {
|
|
196
|
+
...data,
|
|
197
|
+
attempts: data.attempts + 1,
|
|
198
|
+
lastAttemptTime: currentTime
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
setStoredData(key, newData);
|
|
203
|
+
checkRateLimit();
|
|
204
|
+
return newData;
|
|
205
|
+
};
|
|
206
|
+
const checkResendCooldown = () => {
|
|
207
|
+
const key = getStorageKey("last_sent");
|
|
208
|
+
const lastSentTime = getStoredData(key);
|
|
209
|
+
if (!lastSentTime) {
|
|
210
|
+
setResendTimeLeft(0);
|
|
211
|
+
return { canResend: true, timeLeft: 0 };
|
|
212
|
+
}
|
|
213
|
+
const currentTime = Date.now();
|
|
214
|
+
const timeSinceLastSent = currentTime - lastSentTime;
|
|
215
|
+
const cooldown = OTP_DEFAULTS.RESEND_COOLDOWN_SECONDS * 1e3;
|
|
216
|
+
const canResend = timeSinceLastSent >= cooldown;
|
|
217
|
+
const timeLeft = canResend ? 0 : Math.ceil((cooldown - timeSinceLastSent) / 1e3);
|
|
218
|
+
setResendTimeLeft(timeLeft);
|
|
219
|
+
return { canResend, timeLeft };
|
|
220
|
+
};
|
|
221
|
+
const recordSentOTP = () => {
|
|
222
|
+
const key = getStorageKey("last_sent");
|
|
223
|
+
setStoredData(key, Date.now());
|
|
224
|
+
updateRateLimit();
|
|
225
|
+
setOtpTimeLeft(OTP_DEFAULTS.EXPIRY_MINUTES * 60);
|
|
226
|
+
setResendTimeLeft(OTP_DEFAULTS.RESEND_COOLDOWN_SECONDS);
|
|
227
|
+
};
|
|
228
|
+
(0, import_react.useEffect)(() => {
|
|
229
|
+
checkRateLimit();
|
|
230
|
+
checkResendCooldown();
|
|
231
|
+
const timer = setInterval(() => {
|
|
232
|
+
setOtpTimeLeft((prev) => Math.max(0, prev - 1));
|
|
233
|
+
const { timeLeft } = checkResendCooldown();
|
|
234
|
+
setResendTimeLeft(timeLeft);
|
|
235
|
+
}, 1e3);
|
|
236
|
+
return () => clearInterval(timer);
|
|
237
|
+
}, [email]);
|
|
238
|
+
const formatTime = (seconds) => {
|
|
239
|
+
const mins = Math.floor(seconds / 60);
|
|
240
|
+
const secs = seconds % 60;
|
|
241
|
+
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
otpTimeLeft,
|
|
245
|
+
resendTimeLeft,
|
|
246
|
+
attemptsLeft,
|
|
247
|
+
isRateLimited,
|
|
248
|
+
rateLimitResetTime,
|
|
249
|
+
formatTime,
|
|
250
|
+
recordSentOTP,
|
|
251
|
+
checkRateLimit
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
255
|
+
0 && (module.exports = {
|
|
256
|
+
InputOTP,
|
|
257
|
+
InputOTPGroup,
|
|
258
|
+
InputOTPSeparator,
|
|
259
|
+
InputOTPSlot,
|
|
260
|
+
useOTP
|
|
261
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
interface EmailConfig {
|
|
2
|
+
transport: {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
secure?: boolean;
|
|
6
|
+
auth: {
|
|
7
|
+
user: string;
|
|
8
|
+
pass: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
defaults?: {
|
|
12
|
+
from?: {
|
|
13
|
+
name: string;
|
|
14
|
+
address: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface SendEmailOptions {
|
|
19
|
+
to: string;
|
|
20
|
+
subject: string;
|
|
21
|
+
html: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
from?: {
|
|
24
|
+
name: string;
|
|
25
|
+
address: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
declare class EmailService {
|
|
29
|
+
private transporter;
|
|
30
|
+
private config;
|
|
31
|
+
constructor(config: EmailConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Verify SMTP connection configuration
|
|
34
|
+
*/
|
|
35
|
+
verifyConnection(): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Send an email
|
|
38
|
+
* @param options - Email options (to, subject, html, text, from)
|
|
39
|
+
* @returns - Result of the send operation
|
|
40
|
+
*/
|
|
41
|
+
sendEmail(options: SendEmailOptions): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
messageId: any;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface OTPData {
|
|
48
|
+
otp: string;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
}
|
|
51
|
+
declare class OTPService {
|
|
52
|
+
private secretKey;
|
|
53
|
+
constructor(secretKey: string);
|
|
54
|
+
/**
|
|
55
|
+
* Generate a numeric OTP of specified length
|
|
56
|
+
* @param length - Length of the OTP (default: 6)
|
|
57
|
+
* @returns - The generated OTP string
|
|
58
|
+
*/
|
|
59
|
+
generateOTP(length?: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* Encrypt OTP data for secure storage/transmission
|
|
62
|
+
* @param otp - The OTP string
|
|
63
|
+
* @param timestamp - The timestamp when OTP was generated (default: now)
|
|
64
|
+
* @returns - Encrypted OTP data string
|
|
65
|
+
*/
|
|
66
|
+
encryptOTP(otp: string, timestamp?: number): string;
|
|
67
|
+
/**
|
|
68
|
+
* Decrypt OTP data
|
|
69
|
+
* @param encryptedData - The encrypted OTP string
|
|
70
|
+
* @returns - Decrypted OTP data object or null if failed
|
|
71
|
+
*/
|
|
72
|
+
decryptOTP(encryptedData: string): OTPData | null;
|
|
73
|
+
/**
|
|
74
|
+
* Verify an OTP against encrypted data
|
|
75
|
+
* @param inputOtp - The OTP provided by the user
|
|
76
|
+
* @param encryptedData - The encrypted OTP data
|
|
77
|
+
* @param expiryMinutes - Expiry time in minutes (default: 5)
|
|
78
|
+
* @returns - Object containing valid status and message
|
|
79
|
+
*/
|
|
80
|
+
verifyOTP(inputOtp: string, encryptedData: string, expiryMinutes?: number): {
|
|
81
|
+
valid: boolean;
|
|
82
|
+
message: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Encrypts a string using AES-256-CBC
|
|
88
|
+
* @param text - The text to encrypt
|
|
89
|
+
* @param secretKey - The 32-character secret key
|
|
90
|
+
* @returns - The encrypted value with IV and encrypted data, base64 encoded
|
|
91
|
+
*/
|
|
92
|
+
declare function encrypt(text: string, secretKey: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Decrypts a string that was encrypted using the encrypt function
|
|
95
|
+
* @param encryptedText - The encrypted text (IV:EncryptedData format)
|
|
96
|
+
* @param secretKey - The 32-character secret key
|
|
97
|
+
* @returns - The decrypted string
|
|
98
|
+
*/
|
|
99
|
+
declare function decrypt(encryptedText: string, secretKey: string): string;
|
|
100
|
+
|
|
101
|
+
declare class IrisMailService {
|
|
102
|
+
email: EmailService;
|
|
103
|
+
otp: OTPService;
|
|
104
|
+
constructor(config: {
|
|
105
|
+
email: EmailConfig;
|
|
106
|
+
secretKey: string;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { type EmailConfig, EmailService, IrisMailService, type OTPData, OTPService, type SendEmailOptions, decrypt, encrypt };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
interface EmailConfig {
|
|
2
|
+
transport: {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
secure?: boolean;
|
|
6
|
+
auth: {
|
|
7
|
+
user: string;
|
|
8
|
+
pass: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
defaults?: {
|
|
12
|
+
from?: {
|
|
13
|
+
name: string;
|
|
14
|
+
address: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface SendEmailOptions {
|
|
19
|
+
to: string;
|
|
20
|
+
subject: string;
|
|
21
|
+
html: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
from?: {
|
|
24
|
+
name: string;
|
|
25
|
+
address: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
declare class EmailService {
|
|
29
|
+
private transporter;
|
|
30
|
+
private config;
|
|
31
|
+
constructor(config: EmailConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Verify SMTP connection configuration
|
|
34
|
+
*/
|
|
35
|
+
verifyConnection(): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Send an email
|
|
38
|
+
* @param options - Email options (to, subject, html, text, from)
|
|
39
|
+
* @returns - Result of the send operation
|
|
40
|
+
*/
|
|
41
|
+
sendEmail(options: SendEmailOptions): Promise<{
|
|
42
|
+
success: boolean;
|
|
43
|
+
messageId: any;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface OTPData {
|
|
48
|
+
otp: string;
|
|
49
|
+
timestamp: number;
|
|
50
|
+
}
|
|
51
|
+
declare class OTPService {
|
|
52
|
+
private secretKey;
|
|
53
|
+
constructor(secretKey: string);
|
|
54
|
+
/**
|
|
55
|
+
* Generate a numeric OTP of specified length
|
|
56
|
+
* @param length - Length of the OTP (default: 6)
|
|
57
|
+
* @returns - The generated OTP string
|
|
58
|
+
*/
|
|
59
|
+
generateOTP(length?: number): string;
|
|
60
|
+
/**
|
|
61
|
+
* Encrypt OTP data for secure storage/transmission
|
|
62
|
+
* @param otp - The OTP string
|
|
63
|
+
* @param timestamp - The timestamp when OTP was generated (default: now)
|
|
64
|
+
* @returns - Encrypted OTP data string
|
|
65
|
+
*/
|
|
66
|
+
encryptOTP(otp: string, timestamp?: number): string;
|
|
67
|
+
/**
|
|
68
|
+
* Decrypt OTP data
|
|
69
|
+
* @param encryptedData - The encrypted OTP string
|
|
70
|
+
* @returns - Decrypted OTP data object or null if failed
|
|
71
|
+
*/
|
|
72
|
+
decryptOTP(encryptedData: string): OTPData | null;
|
|
73
|
+
/**
|
|
74
|
+
* Verify an OTP against encrypted data
|
|
75
|
+
* @param inputOtp - The OTP provided by the user
|
|
76
|
+
* @param encryptedData - The encrypted OTP data
|
|
77
|
+
* @param expiryMinutes - Expiry time in minutes (default: 5)
|
|
78
|
+
* @returns - Object containing valid status and message
|
|
79
|
+
*/
|
|
80
|
+
verifyOTP(inputOtp: string, encryptedData: string, expiryMinutes?: number): {
|
|
81
|
+
valid: boolean;
|
|
82
|
+
message: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Encrypts a string using AES-256-CBC
|
|
88
|
+
* @param text - The text to encrypt
|
|
89
|
+
* @param secretKey - The 32-character secret key
|
|
90
|
+
* @returns - The encrypted value with IV and encrypted data, base64 encoded
|
|
91
|
+
*/
|
|
92
|
+
declare function encrypt(text: string, secretKey: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Decrypts a string that was encrypted using the encrypt function
|
|
95
|
+
* @param encryptedText - The encrypted text (IV:EncryptedData format)
|
|
96
|
+
* @param secretKey - The 32-character secret key
|
|
97
|
+
* @returns - The decrypted string
|
|
98
|
+
*/
|
|
99
|
+
declare function decrypt(encryptedText: string, secretKey: string): string;
|
|
100
|
+
|
|
101
|
+
declare class IrisMailService {
|
|
102
|
+
email: EmailService;
|
|
103
|
+
otp: OTPService;
|
|
104
|
+
constructor(config: {
|
|
105
|
+
email: EmailConfig;
|
|
106
|
+
secretKey: string;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { type EmailConfig, EmailService, IrisMailService, type OTPData, OTPService, type SendEmailOptions, decrypt, encrypt };
|