Skip to content

Commit dba4f5a

Browse files
committed
Normalize equivalent domain names
1 parent a5f6696 commit dba4f5a

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ CHANGELOG
55
------------------
66

77
* Added `PxpFinancial` and `Trustpay` to the `Processor` enum.
8+
* Equivalent domain names are now normalized when `hashAddress` is used.
9+
For example, `googlemail.com` will become `gmail.com`.
810

911
6.0.0 (2023-12-05)
1012
------------------

src/request/email.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ArgumentError } from '../errors';
2+
import crypto from 'crypto';
23
import Email from './email';
34

45
describe('Email()', () => {
@@ -66,6 +67,10 @@ describe('Email()', () => {
6667
expect(email.domain).toBe('bar.com');
6768
});
6869

70+
const md5 = (s: string): string => {
71+
return crypto.createHash('md5').update(s).digest('hex');
72+
};
73+
6974
const normalizeTests = [
7075
{
7176
@@ -143,6 +148,11 @@ describe('Email()', () => {
143148
// 'test' is rejected as invalid.
144149
// 'test@' is rejected as invalid.
145150
// 'test@.' is rejected as invalid.
151+
{
152+
153+
md5: md5('[email protected]'),
154+
domain: 'googlemail.com',
155+
},
146156
];
147157

148158
test.each(normalizeTests)('%p', (arg) => {

src/request/email.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ export default class Email implements EmailProps {
4545
'putlook.com': 'outlook.com',
4646
};
4747

48+
private static readonly equivalentDomains: { [key: string]: string } = {
49+
'googlemail.com': 'gmail.com',
50+
'pm.me': 'protonmail.com',
51+
'proton.me': 'protonmail.com',
52+
'yandex.by': 'yandex.ru',
53+
'yandex.com': 'yandex.ru',
54+
'yandex.kz': 'yandex.ru',
55+
'yandex.ua': 'yandex.ru',
56+
'ya.ru': 'yandex.ru',
57+
};
58+
4859
public constructor(email: EmailProps) {
4960
if (email.address != null && !isEmail(email.address)) {
5061
throw new ArgumentError('`email.address` is an invalid email address');
@@ -107,6 +118,10 @@ export default class Email implements EmailProps {
107118
domain = Email.typoDomains[domain];
108119
}
109120

121+
if (Object.prototype.hasOwnProperty.call(Email.equivalentDomains, domain)) {
122+
domain = Email.equivalentDomains[domain];
123+
}
124+
110125
return domain;
111126
}
112127
}

0 commit comments

Comments
 (0)