-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (70 loc) · 1.99 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
const crypto = require( 'crypto-js' );
const INSTRUMENT_TYPES = {
CREDITCARD: 'CREDITCARD',
BANKACCOUNT: 'BANKACCOUNT'
};
const CARD_SCHEMES = {
MASTERCARD: "MASTERCARD",
VISA: "VISA",
AMEX: "AMEX",
DINERS: "DINERS"
};
const CC_MASK_SCHEMES = {
FOUR_THREE: {
START: 4,
END: 3,
TOTAL_MASKED: 7
},
ONE_TWO: {
START: 1,
END: 2,
TOTAL_MASKED: 3
}
}; // end CC_MASK_SCHEMES
let numString = new RegExp(/^\d+$/);
let bsbString = new RegExp(/^\d{3}-?\d{3}$/);
/**
* used to mask a number with specs from a supplied scheme
* @param identifier
* @param maskScheme
* @returns {string}
*/
module.exports.maskIdentifier = function( identifier, maskScheme = "FOUR_THREE" ) {
let stars = '*'.repeat( identifier.length - CC_MASK_SCHEMES[maskScheme].TOTAL_MASKED );
let maskedIdentifier = identifier.substring( 0, CC_MASK_SCHEMES[maskScheme].START ) + stars;
return maskedIdentifier + identifier.substring(identifier.length - CC_MASK_SCHEMES[maskScheme].END);
}; // end maskIdentifier
/**
* encrypt any string. presently uses a string passed in from SSM
* @param clearText
* @param encKey
* @returns {*}
*/
module.exports.encryptString = function( clearText, encKey ) {
return crypto.AES.encrypt( clearText, encKey ).toString();
}; // end encryptString
/**
* decrypt a string using the provided
* @param cypherText
* @param encKey
* @returns {*}
*/
module.exports.decryptString = function( cypherText, encKey ) {
return crypto.AES.decrypt(cypherText.toString(), encKey ).toString( crypto.enc.Utf8 );
}; // end decryptString
/**
* boolean test that the number could be a BSB
* @param candidateBsb
* @returns {boolean}
*/
module.exports.isBsb = function( candidateBsb ) {
return bsbString.test( candidateBsb )
}; // end isBsb
/**
* Boolean test that a string is in fact a regular number
* @param candidateString
* @returns {boolean}
*/
module.exports.isNumberString = function( candidateString ) {
return numString.test( candidateString )
}; // end isNumberString