@ellipticltd/aml-utils 0.8.0 → 0.9.0-EN-2570.1
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/.circleci/config.yml +37 -4
- package/.eslintrc +30 -6
- package/.huskyrc +5 -0
- package/.mocharc.json +3 -0
- package/.releaserc.json +18 -0
- package/README.md +39 -0
- package/commitlint.config.js +1 -0
- package/dist/errors/errors.d.ts +9 -0
- package/dist/errors/errors.js +42 -0
- package/dist/errors/errors.spec.d.ts +1 -0
- package/dist/errors/errors.spec.js +23 -0
- package/dist/file-parser/__tests/file-parser.spec.d.ts +1 -0
- package/dist/file-parser/__tests/file-parser.spec.js +118 -0
- package/dist/file-parser/__tests/parse-row.spec.d.ts +1 -0
- package/dist/file-parser/__tests/parse-row.spec.js +29 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +1 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.js +78 -0
- package/dist/file-parser/errors.d.ts +3 -0
- package/dist/file-parser/errors.js +11 -0
- package/dist/file-parser/file-parser.d.ts +8 -0
- package/dist/file-parser/file-parser.js +68 -0
- package/dist/file-parser/parse-row.d.ts +2 -0
- package/dist/file-parser/parse-row.js +39 -0
- package/dist/file-parser/sanitzeRows.d.ts +3 -0
- package/dist/file-parser/sanitzeRows.js +18 -0
- package/dist/formatting/formatting.d.ts +2 -0
- package/dist/formatting/formatting.js +17 -0
- package/dist/formatting/formatting.spec.d.ts +1 -0
- package/dist/formatting/formatting.spec.js +37 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/middleware/middleware.d.ts +4 -0
- package/dist/middleware/middleware.js +22 -0
- package/dist/orm-helpers/ormHelpers.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.js +17 -0
- package/dist/orm-helpers/ormHelpers.spec.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.spec.js +38 -0
- package/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +203 -0
- package/dist/validations/validations.d.ts +118 -0
- package/dist/validations/validations.js +300 -0
- package/dist/validations/validations.spec.d.ts +1 -0
- package/dist/validations/validations.spec.js +287 -0
- package/lib/errors/errors.spec.js +37 -0
- package/lib/file-parser/__tests/file-parser.spec.js +107 -0
- package/lib/file-parser/__tests/parse-row.spec.js +35 -0
- package/lib/file-parser/__tests/sanitize-rows.spec.js +88 -0
- package/lib/file-parser/errors.ts +7 -0
- package/lib/file-parser/file-parser.ts +84 -0
- package/lib/file-parser/parse-row.ts +52 -0
- package/lib/file-parser/sanitzeRows.ts +32 -0
- package/lib/formatting/formatting.spec.js +45 -0
- package/lib/index.ts +17 -0
- package/lib/{middleware.js → middleware/middleware.js} +1 -1
- package/lib/orm-helpers/ormHelpers.spec.js +41 -0
- package/lib/{types.js → types/types.js} +2 -2
- package/lib/{validations.js → validations/validations.js} +12 -8
- package/lib/validations/validations.spec.js +366 -0
- package/package.json +28 -13
- package/tsconfig.json +26 -0
- package/.idea/aml-utils.iml +0 -8
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -52
- package/index.d.ts +0 -1
- package/index.js +0 -8
- /package/lib/{errors.js → errors/errors.js} +0 -0
- /package/lib/{formatting.js → formatting/formatting.js} +0 -0
- /package/lib/{ormHelpers.js → orm-helpers/ormHelpers.js} +0 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import validations from './validations';
|
|
2
|
+
|
|
3
|
+
const chai = require('chai');
|
|
4
|
+
|
|
5
|
+
const { expect, assert } = chai;
|
|
6
|
+
|
|
7
|
+
describe('Validations', () => {
|
|
8
|
+
describe('global checks', () => {
|
|
9
|
+
describe('exists', () => {
|
|
10
|
+
it('should return true when passed any value', () => validations.exists('x').should.be.true);
|
|
11
|
+
|
|
12
|
+
it('should return false when not passed a value', () => validations.exists().should.be.false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('nonEmpty', () => {
|
|
16
|
+
it('should return true when passed any value with a length', () => validations.nonEmpty('x').should.be.true
|
|
17
|
+
&& validations.nonEmpty(['x']));
|
|
18
|
+
|
|
19
|
+
it('should return false when passed a value without a length', () => validations.nonEmpty().should.be.false
|
|
20
|
+
&& validations.nonEmpty({}).should.be.false
|
|
21
|
+
&& validations.nonEmpty(null).should.be.false
|
|
22
|
+
&& validations.nonEmpty(undefined).should.be.false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('isNonEmptyString', () => {
|
|
26
|
+
it('should return true when passed a string of any length', () => validations.isNonEmptyString('x').should.be.true
|
|
27
|
+
&& validations.isNonEmptyString('Do not go gentle into that good night, Old age should burn and rage at close of day; Rage, rage against the dying of the light.').should.be.true);
|
|
28
|
+
|
|
29
|
+
it('should return false when passed an empty string or something that is not a string', () => validations.isNonEmptyString('').should.be.false
|
|
30
|
+
&& validations.isNonEmptyString(['x']).should.be.false
|
|
31
|
+
&& validations.isNonEmptyString({ key: 'val' }).should.be.false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('ensureShortEnough', () => {
|
|
35
|
+
it('should return true when the given string is shorter in length than the given length', () => validations.ensureShortEnough(3, 'foo').should.be.true
|
|
36
|
+
&& validations.ensureShortEnough(3, 'fo').should.be.true);
|
|
37
|
+
|
|
38
|
+
it('should throw a BadRequest error if the given string is longer than the given length', () => {
|
|
39
|
+
expect(() => validations.ensureShortEnough(3, 'foo!')).to.throw('Max query size exceeded: 4 / 3');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should throw a BadRequest error if the given string is null or undefined', () => {
|
|
43
|
+
expect(() => validations.ensureShortEnough(3, null)).to.throw('Max query size exceeded: undefined / 3');
|
|
44
|
+
expect(() => validations.ensureShortEnough(3, undefined)).to.throw('Max query size exceeded: undefined / 3');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('ensure', () => {
|
|
49
|
+
it('should return true if the first argument is not null or undefined', () => validations.ensure('thing', 'Error message').should.be.true
|
|
50
|
+
&& validations.ensure(['array'], 'Error message').should.be.true
|
|
51
|
+
&& validations.ensure({ key: 'val' }).should.be.true);
|
|
52
|
+
it('should throw a BadRequest error if the first argument is null or undefined', () => {
|
|
53
|
+
expect(() => validations.ensure(null, 'Error message').to.throw('Error message'));
|
|
54
|
+
expect(() => validations.ensure(undefined, 'Error message').to.throw('Error message'));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('isSafeString', () => {
|
|
58
|
+
it('should return true if the first argument is a safe string', () => {
|
|
59
|
+
validations.isSafeString('aaaaa').should.be.true;
|
|
60
|
+
validations.isSafeString('Customer reference').should.be.true;
|
|
61
|
+
validations.isSafeString('Safe-String-01827!@').should.be.true;
|
|
62
|
+
});
|
|
63
|
+
it('should return false if the first argument is a safe string', () => {
|
|
64
|
+
validations.isSafeString('{customer}').should.be.false;
|
|
65
|
+
validations.isSafeString('<string>').should.be.false;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('check', () => {
|
|
71
|
+
describe('matches', () => {
|
|
72
|
+
it('should return true when passed two arrays that exactly match', () => validations.check.matches([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], 'error message').should.be.true);
|
|
73
|
+
|
|
74
|
+
it('should throw an error when passed two arrays that do not exactly match', () => {
|
|
75
|
+
expect(() => validations.check.matches([1, 2, 3, 4], [1, 2, 3, 4, 5], 'Error message').to.throw('Error message'));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('wasFound', () => {
|
|
80
|
+
it('should return the string passed if this is not null', () => {
|
|
81
|
+
expect(validations.check.wasFound()('string')).to.equal('string');
|
|
82
|
+
});
|
|
83
|
+
it('should throw an error if the item is null', () => {
|
|
84
|
+
expect(() => validations.check.wasFound('no value')()).to.throw('Unknown no value');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('wasCreated', () => {
|
|
89
|
+
it('should return the array passed if it is not empty', () => {
|
|
90
|
+
expect(validations.check.wasCreated()([1, 2, 3])).to.eql([1, 2, 3]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should throw an error if the array is empty', () => {
|
|
94
|
+
expect(() => validations.check.wasCreated('Oh no! No array!')([])).to.throw('Oh no! No array!');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('isTrue', () => {
|
|
99
|
+
const count = 2;
|
|
100
|
+
|
|
101
|
+
it('should return true when the first arg is truthy', () => {
|
|
102
|
+
assert(validations.check.isTrue(count === 2, 'Count equals 2'), 'isTrue should be false');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should throw an error when the first arg is falsy', () => {
|
|
106
|
+
expect(() => validations.check.isTrue(count <= 1, 'Count is greater than 1')).to.throw('Count is greater than 1');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('isFalse', () => {
|
|
111
|
+
const count = 2;
|
|
112
|
+
|
|
113
|
+
it('should return true when the first arg is falsy', () => {
|
|
114
|
+
assert(validations.check.isFalse(count === 3, 'Count should not equal 3'), 'isFalse should be true');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should throw an error when the first arg is truthy', () => {
|
|
118
|
+
expect(() => validations.check.isFalse(count > 1, 'Count should be greater than 1')).to.throw('Count should be greater than 1');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('isCustomerReference', () => {
|
|
123
|
+
it('should return true if the string is longer than 0 and less than or equal to 100 characters', () => {
|
|
124
|
+
assert(validations.isCustomerReference('1'), 'isCustomerReference fails when the string length is 1');
|
|
125
|
+
assert(validations.isCustomerReference('Spots of sunshine lie on the surface of the water dance, dance, and their reflections wobble.'), 'isCustomerReference fails when the string length is 100');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should return false when passed an empty string or one longer than 100 characters, or a non-string', () => {
|
|
129
|
+
assert(!validations.isCustomerReference(''), 'isCustomerReference passes when passed an empty string');
|
|
130
|
+
assert(!validations.isCustomerReference('Little spots of sunshine lie on the surface of the water and dance, dance, and their reflections wobble deliciously over the ceiling;'), 'isCustomerReference passes with string over 100 characters');
|
|
131
|
+
assert(!validations.isCustomerReference(['array']), 'isCustomerReference passes when passed a non-string');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe('isCustomerLabelName', () => {
|
|
136
|
+
it('should return true if the string is longer than 0 and less than or equal to 50 characters', () => {
|
|
137
|
+
assert(validations.isCustomerLabelName('1'), 'isCustomerLabelName fails when the string length is 1');
|
|
138
|
+
assert(validations.isCustomerLabelName('William Shakespeare was poet, playwright and actor'), 'isCustomerLabelName fails when the string length is 50');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should return false when passed an empty string or one longer than 50 characters, or a non-string', () => {
|
|
142
|
+
assert(!validations.isCustomerLabelName(''), 'isCustomerLabelName passes when passed an empty string');
|
|
143
|
+
assert(!validations.isCustomerLabelName("Many of Shakespeare's plays were published in editions of varying quality and accuracy in his lifetime."), 'isCustomerLabelName passes with string over 50 characters');
|
|
144
|
+
assert(!validations.isCustomerLabelName(['array']), 'isCustomerLabelName passes when passed a non-string');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe('BCH', () => {
|
|
150
|
+
describe('isAddress', () => {
|
|
151
|
+
it('should correctly validate valid BCH addresses', () => validations.bitcoinCash.isAddress('bitcoincash:qrrfmt57avxfd2476gqxqq54djtcvjuzjc2qtsrzcw').should.be.true
|
|
152
|
+
&& validations.bitcoinCash.isAddress('qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq').should.be.true);
|
|
153
|
+
|
|
154
|
+
it('should correctly validate an incorrect BCH address', () => validations.bitcoinCash.isAddress('qqrxa0h9jqnc7v4wmj3y7w9l36u8gnnjulq').should.be.false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('isTxHash', () => {
|
|
158
|
+
it('should correctly validate a valid BCH hash', () => validations.bitcoinCash.isTxHash('a32c4d2f9f2e322f19867dbacb7609a1be63c914b8f41775082b50d3ee1a0ce6').should.be.true);
|
|
159
|
+
|
|
160
|
+
it('should correctly validate an incorrect BCH hash', () => validations.bitcoinCash.isTxHash('cd1bdc201022ca9386d8757b1c49ecc6ee3769cad2d42ab6e7f9e7bd831').should.be.false);
|
|
161
|
+
|
|
162
|
+
it('should return false when passed a non-hex string', () => validations.bitcoinCash.isTxHash('Not a hex string!').should.be.false);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('BNB', () => {
|
|
167
|
+
describe('isAddress', () => {
|
|
168
|
+
it('should correctly validate valid BNB addresses', () => validations.binanceCoin.isAddress('bnb1z35wusfv8twfele77vddclka9z84ugywug48gn').should.be.true);
|
|
169
|
+
|
|
170
|
+
it('should correctly validate an incorrect BNB address', () => validations.binanceCoin.isAddress('bnb1z35wusfv8twfele77vddclka9z84ugywug48gn1').should.be.false);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('isTxHash', () => {
|
|
174
|
+
it('should correctly validate a valid BNB hash', () => validations.binanceCoin.isTxHash('E68C2D178F989DE296FA1B513D1AA138B234C436B52E0D755C6664A70F7EEF7B').should.be.true);
|
|
175
|
+
|
|
176
|
+
it('should correctly validate an incorrect BNB hash', () => validations.binanceCoin.isTxHash('E68C2D178F989DE296FA1B513D1AA138B234C436B52E0D755C6664A70F7EEF7B1').should.be.false);
|
|
177
|
+
|
|
178
|
+
it('should return false when passed a non-hex string', () => validations.binanceCoin.isTxHash('Not a hex string!').should.be.false);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('BTC', () => {
|
|
183
|
+
describe('isAddress', () => {
|
|
184
|
+
it('should correctly validate a valid BTC address', () => validations.bitcoin.isAddress('1LFnX5KT4CMKud7KB9xaXFZFkD3H8bUD16').should.be.true);
|
|
185
|
+
|
|
186
|
+
it('should correctly validate an incorrect BTC address', () => validations.bitcoin.isAddress('1LFnX5KT4CMKud7KB9xaXFZFkD3H8b').should.be.false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('isBech32Address', () => {
|
|
190
|
+
it('should correctly validate a Bech32 address', () => validations.bitcoin.isBech32Address('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.true);
|
|
191
|
+
it('should correctly validate an invalide Bech32 address', () => validations.bitcoin.isBech32Address('4ef47f6eb681d5d9fa2f7e16336cd629303c635e8da51e425b76088be9c8744c').should.be.false);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('isHDPublicKey', () => {
|
|
195
|
+
it('should return true when passed an HD public key', () => validations.bitcoin.isHDPublicKey('xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi').should.be.true);
|
|
196
|
+
it('should return false when not passed an HD public key', () => validations.bitcoin.isHDPublicKey('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.false);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('isPublicKey', () => {
|
|
200
|
+
it('should return true when passed a public key', () => validations.bitcoin.isPublicKey('046c04c02f1138f440e8c5e9099db938bfba93d0389528bb7f6bf423ae203a2edcfba133f0409023d7ea13ac01c5aeedaf0bbfbeb8b82e9b48410d93a296da5b0c').should.be.true);
|
|
201
|
+
it('should return false when not passed a public key', () => validations.bitcoin.isPublicKey('1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm').should.be.false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe('isTxHash', () => {
|
|
205
|
+
it('should correctly validate a valid BTC hash', () => validations.bitcoin.isTxHash('835346f3ea00a23df60ca5dc24afce67810c792ac4505e544410d4b19e7c95a0').should.be.true);
|
|
206
|
+
it('should correctly validate an incorrect BTC hash', () => validations.bitcoin.isTxHash('835346f3ea00a23df60caafce67810c792ac4505e544410d4b19e7c95a0').should.be.false);
|
|
207
|
+
it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxHex('Definitely not a hex string').should.be.false);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('isTxHex', () => {
|
|
211
|
+
const hex = '0100000002d8c8df6a6fdd2addaf589a83d860f18b44872d13ee6ec3526b2b470d42a96d4d000000008b483045022100b31557e47191936cb14e013fb421b1860b5e4fd5d2bc5ec1938f4ffb1651dc8902202661c2920771fd29dd91cd4100cefb971269836da4914d970d333861819265ba014104c54f8ea9507f31a05ae325616e3024bd9878cb0a5dff780444002d731577be4e2e69c663ff2da922902a4454841aa1754c1b6292ad7d317150308d8cce0ad7abffffffff2ab3fa4f68a512266134085d3260b94d3b6cfd351450cff021c045a69ba120b2000000008b4830450220230110bc99ef311f1f8bda9d0d968bfe5dfa4af171adbef9ef71678d658823bf022100f956d4fcfa0995a578d84e7e913f9bb1cf5b5be1440bcede07bce9cd5b38115d014104c6ec27cffce0823c3fecb162dbd576c88dd7cda0b7b32b0961188a392b488c94ca174d833ee6a9b71c0996620ae71e799fc7c77901db147fa7d97732e49c8226ffffffff02c0175302000000001976a914a3d89c53bb956f08917b44d113c6b2bcbe0c29b788acc01c3d09000000001976a91408338e1d5e26db3fce21b011795b1c3c8a5a5d0788ac00000000';
|
|
212
|
+
it('should return true if passed a hex string Tx hash', () => validations.bitcoin.isTxHex(hex).should.be.true);
|
|
213
|
+
it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxHex('definitelyNotAHexString').should.be.false);
|
|
214
|
+
it('should return false if the string passed is a hex string, but is not a tx hash', () => validations.bitcoin.isTxHex('4ef47f6eb681d5d9fa2f7e16336cd629303c635e8da51e425b76088be9c8744c').should.be.false);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('isHDPath', () => {
|
|
218
|
+
it('should return true when passed a valid HDPrivateKey path', () => validations.bitcoin.isHDPath('xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'));
|
|
219
|
+
it('should return false when passed a string that is not a valid HDPrivateKey path', () => validations.bitcoin.isHDPath('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe('isScriptHex', () => {
|
|
223
|
+
it('should return true when passed a script hex', () => validations.bitcoin.isScriptHex('01000000011e2e8cfdf21d68f90974cd557a30c11894cc8cfec5cd5330e41846c2c84566bd000000006b4830450221009f61f453f44e807fdc538ca21710393d34005dd5709dabd8b6b9ccf09ea0b36a0220420d91a33f43d7b979471220e12cd1025975bd2e6c0bf2a14eb65ad89d578104012102de8f92034b9b3c956c1896d23a628537561e29faa772438aac2265c91ede6519ffffffff0118566202000000001976a914b27f04e510293c3e530e7b7bdf71f59118030e1e88ac00000000').should.be.true);
|
|
224
|
+
it('should return false if the string passed is not a hex string', () => validations.bitcoin.isScriptHex('definitelyNotAHexString').should.be.false);
|
|
225
|
+
it('should return false if the string passed is a hex string, but is not a script hex', () => validations.bitcoin.isScriptHex('mpXwg4jMtRhuSpVq4xS3HFHmCmWp9NyGKt').should.be.false);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('isTxSignature', () => {
|
|
229
|
+
it('should return true when passed a tx hash that includes a signature', () => validations.bitcoin.isTxSignature('304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d1090db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501').should.be.true);
|
|
230
|
+
it('should return false when passed a tx hash that does not include a signature', () => validations.bitcoin.isTxSignature('f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6').should.be.false);
|
|
231
|
+
it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxSignature('definitelyNotAHexString').should.be.false);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('isBlockHeight', () => {
|
|
235
|
+
it('should return true when passed a value greater than or equal to 0', () => validations.bitcoin.isBlockHeight(986789).should.be.true
|
|
236
|
+
&& validations.bitcoin.isBlockHeight('987654').should.be.true);
|
|
237
|
+
it('should return false when passed a value that is not greater than or equal to 0', () => validations.bitcoin.isBlockHeight(null).should.be.false
|
|
238
|
+
&& validations.bitcoin.isBlockHeight('string').should.be.false);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe('ETH', () => {
|
|
243
|
+
describe('isAddress', () => {
|
|
244
|
+
it('should return true if the address evaluates as a web3 address', () => validations.ethereum.isAddress('0xa6Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.true);
|
|
245
|
+
it('should return false if the address does not evaluate to a web3 address', () => validations.ethereum.isAddress('Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.false);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('isBlockHash', () => {
|
|
249
|
+
it('should return true when given a valid hash', () => validations.ethereum.isBlockHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.true);
|
|
250
|
+
it('should return false when given an vinalid hash', () => validations.ethereum.isBlockHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489eb0e').should.be.false);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe('isTxHash', () => {
|
|
254
|
+
it('should correctly validate a valid ETH hash', () => validations.ethereum.isTxHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.true);
|
|
255
|
+
|
|
256
|
+
it('should correctly validate an incorrect ETH hash', () => validations.ethereum.isTxHash('0xec6491abd46a1a9a71b7896fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.false);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
describe('isAddressCode', () => {
|
|
260
|
+
it('should return true if the string is a hex address', () => validations.ethereum.isAddressCode('0xa6Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.true);
|
|
261
|
+
it('should return false if the string is not a hex address', () => validations.ethereum.isAddressCode('0xa6Bc4b3fe7F27yu124d30D896Fe4457711e9d214').should.be.false);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('isValidWeiAmount', () => {
|
|
265
|
+
it('should return true when passed an amount that evaluates to wei', () => validations.ethereum.isValidWeiAmount('7000000000000000').should.be.true);
|
|
266
|
+
it('should return false when passed an amount that is not valid in wei', () => validations.ethereum.isValidWeiAmount(7000000000000000).should.be.false
|
|
267
|
+
&& validations.ethereum.isValidWeiAmount('1000.00').should.be.false);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('LTC', () => {
|
|
272
|
+
describe('isAddress', () => {
|
|
273
|
+
it('should correctly validate valid LTC addresses', () => validations.litecoin.isAddress('LMR7przNNMS3GpaD6Ygq64NxbsJsZAqGgM').should.be.true);
|
|
274
|
+
|
|
275
|
+
it('should correctly validate an incorrect LTC address', () => validations.litecoin.isAddress('t1t8BzkNb8d98o8kpbwrjtUjMX3GMF').should.be.false);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('isTxHash', () => {
|
|
279
|
+
it('should correctly validate a valid LTC hash', () => validations.litecoin.isTxHash('b0b858b34675cc8f851e6a2174295ada574837422538efe9ca83ef405d2faf29').should.be.true);
|
|
280
|
+
|
|
281
|
+
it('should correctly validate an incorrect LTC hash', () => validations.litecoin.isTxHash('b0b858b34675cc8f851e6a2295ada574837422538efe9ca83ef405d2faf29').should.be.false);
|
|
282
|
+
|
|
283
|
+
it('should return false when passed a non-hex string', () => validations.litecoin.isTxHash('Not a hex code here').should.be.false);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('XLM', () => {
|
|
288
|
+
describe('isAddress', () => {
|
|
289
|
+
it('should correctly validate valid XLM addresses', () => validations.stellar.isAddress('GBH4TZYZ4IRCPO44CBOLFUHULU2WGALXTAVESQA6432MBJMABBB4GIYI').should.be.true);
|
|
290
|
+
|
|
291
|
+
it('should correctly validate an incorrect XLM address', () => validations.stellar.isAddress('GBH4TZYZ4IRCPO44CAAAAAAULU2WGALXTAVESQA6432MBJMABBB4GIYI').should.be.false);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
describe('isTxHash', () => {
|
|
295
|
+
it('should correctly validate a valid XLM hash', () => validations.stellar.isTxHash('dcf208070966a0f04dbff0be6abe5bc7ea2d77f16167e89e1869a8efc68ebe44').should.be.true);
|
|
296
|
+
|
|
297
|
+
it('should correctly validate an incorrect XLM hash', () => validations.stellar.isTxHash('8ee1f64137b12d07f8d2ddd3460d78ecbe37ba671aa4e54af34de935cc2bba2ca').should.be.false);
|
|
298
|
+
|
|
299
|
+
it('should return false when passed a non-hex string', () => validations.stellar.isTxHash('Yet again this is not a hex string').should.be.false);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe('XRP', () => {
|
|
304
|
+
describe('isAddress', () => {
|
|
305
|
+
it('should correctly validate valid XRP addresses', () => validations.ripple.isAddress('rDV3RhpWznRCmtpD17RNxg6t4Hg8NPV8mF').should.be.true);
|
|
306
|
+
|
|
307
|
+
it('should correctly validate an incorrect XRP address', () => validations.ripple.isAddress('rDV3RhpWznRCmtpD17RNxg0t4Hg8NPV8mF').should.be.false);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe('isTxHash', () => {
|
|
311
|
+
it('should correctly validate a valid XRP hash', () => validations.ripple.isTxHash('C6593DD2A32ED5120DF1FE80665B84A9CCAF06ADDC2EF89F720CBAC3E8069C0E').should.be.true);
|
|
312
|
+
|
|
313
|
+
it('should correctly validate an incorrect XRP hash', () => validations.ripple.isTxHash('C6593DD2A32ED5120DF1FE84A9CCAF06ADDC2EF89F720CBAC3E8069C0E').should.be.false);
|
|
314
|
+
|
|
315
|
+
it('should return false when passed a non-hex string', () => validations.ripple.isTxHash('Yet again this is not a hex string').should.be.false);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe('ZEC', () => {
|
|
320
|
+
describe('isAddress', () => {
|
|
321
|
+
it('should correctly validate valid ZEC addresses', () => validations.zcash.isAddress('t1Jxptj7GnXQRsLNH5wWnDrGwEipEB3aZtf').should.be.true);
|
|
322
|
+
|
|
323
|
+
it('should correctly validate an incorrect ZEC address', () => validations.zcash.isAddress('t1Jxptj7GnXQRsLNH5wWnDrGwEipEB3aZtf1').should.be.false);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('isTxHash', () => {
|
|
327
|
+
it('should correctly validate a valid ZEC hash', () => validations.zcash.isTxHash('715c23949b85581de432f174a9e7f4d3f9e74b008064e2c68e7a52b1ec38e961').should.be.true);
|
|
328
|
+
|
|
329
|
+
it('should correctly validate an incorrect ZEC hash', () => validations.zcash.isTxHash('715c23949b85581de432f174a9e7f4d3f9e74b008064e2c68e7a52b1ec38e9611').should.be.false);
|
|
330
|
+
|
|
331
|
+
it('should return false when passed a non-hex string', () => validations.zcash.isTxHash('Yet again this is not a hex string').should.be.false);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe('ZEN', () => {
|
|
336
|
+
describe('isAddress', () => {
|
|
337
|
+
it('should correctly validate valid ZEN addresses', () => validations.horizen.isAddress('znUovxhrE91tep6D7YtgSc3XJZoYQLVDwVn').should.be.true);
|
|
338
|
+
|
|
339
|
+
it('should correctly validate an incorrect ZEN address', () => validations.horizen.isAddress('znUovxhrE91tep6D7YtgSc3XJZoYQLVDwVn1').should.be.false);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe('isTxHash', () => {
|
|
343
|
+
it('should correctly validate a valid ZEN hash', () => validations.horizen.isTxHash('e5d31deb3fee023758f0b79d06489df975fce9aa53351b9b5c8491e4c33c74b7').should.be.true);
|
|
344
|
+
|
|
345
|
+
it('should correctly validate an incorrect ZEN hash', () => validations.horizen.isTxHash('e5d31deb3fee023758f0b79d06489df975fce9aa53351b9b5c8491e4c33c74b71').should.be.false);
|
|
346
|
+
|
|
347
|
+
it('should return false when passed a non-hex string', () => validations.horizen.isTxHash('Yet again this is not a hex string').should.be.false);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe('ZIL', () => {
|
|
352
|
+
describe('isAddress', () => {
|
|
353
|
+
it('should correctly validate valid ZIL addresses', () => validations.zilliqa.isAddress('zil1tw5rpejf96e76ty93l7c3dn0g79h2qhhdm28a4').should.be.true);
|
|
354
|
+
|
|
355
|
+
it('should correctly validate an incorrect ZIL address', () => validations.zilliqa.isAddress('0x14456246cc53d31f0a2EB00FA0248F7aEbD3fa8').should.be.false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe('isTxHash', () => {
|
|
359
|
+
it('should correctly validate a valid ZIL hash', () => validations.zilliqa.isTxHash('0xb9a04481c546258e339f8ce4cccdee3f179cc37a8f099f0608baf39e0a819f75').should.be.true);
|
|
360
|
+
|
|
361
|
+
it('should correctly validate an incorrect ZIL hash', () => validations.zilliqa.isTxHash('0xb9a04481c546258e339f8ce4cccdee3f179cc37a8f099f0608baf39e0a819f7').should.be.false);
|
|
362
|
+
|
|
363
|
+
it('should return false when passed a non-hex string', () => validations.zilliqa.isTxHash('Yet again this is not a hex string').should.be.false);
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ellipticltd/aml-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-EN-2570.1",
|
|
4
4
|
"description": "Utilities, helpers, validations, type-checking, etc",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "10.1.0",
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
"url": "git+ssh://git@bitbucket.org/elliptic/aml-utils.git"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://bitbucket.org/elliptic/aml-utils#readme",
|
|
14
|
-
"main": "index.js",
|
|
14
|
+
"main": "dist/index.js",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"build:dev": "tsc --watch",
|
|
18
|
+
"test:unit": "ts-mocha --reporter spec \"lib/**/*.spec.js\" --watch-extensions js,ts",
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"lint": "./node_modules/.bin/eslint --color 'lib/**/*.{js,ts}' 'test/**/*.js' ",
|
|
20
21
|
"test": "nyc npm run test:unit && nyc report --reporter=html",
|
|
21
22
|
"coverage": "nyc npm run test:unit && nyc report --reporter=lcov --reporter=text-lcov | codecov --pipe"
|
|
22
23
|
},
|
|
@@ -34,18 +35,32 @@
|
|
|
34
35
|
"web3-utils": "1.0.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"
|
|
38
|
+
"@commitlint/cli": "^11.0.0",
|
|
39
|
+
"@commitlint/config-angular": "^11.0.0",
|
|
40
|
+
"@commitlint/config-conventional": "^11.0.0",
|
|
41
|
+
"@semantic-release/git": "^9.0.0",
|
|
42
|
+
"@types/chai": "^4.2.14",
|
|
43
|
+
"@types/lodash": "^4.14.164",
|
|
44
|
+
"@types/mocha": "^8.0.3",
|
|
45
|
+
"@typescript-eslint/parser": "^4.6.1",
|
|
46
|
+
"chai": "^4.2.0",
|
|
38
47
|
"codecov": "^3.6.1",
|
|
39
|
-
"coffee-script": "1.12.7",
|
|
40
48
|
"eslint": "^6.6.0",
|
|
41
|
-
"eslint-config-airbnb": "^
|
|
42
|
-
"eslint-
|
|
49
|
+
"eslint-config-airbnb-base": "^14.2.0",
|
|
50
|
+
"eslint-import-resolver-typescript": "^2.3.0",
|
|
43
51
|
"eslint-plugin-coffeescript": "^1.0.0",
|
|
44
52
|
"eslint-plugin-import": "^2.18.2",
|
|
45
53
|
"eslint-plugin-jsx-a11y": "^6.2.3",
|
|
46
|
-
"eslint-plugin-
|
|
47
|
-
"
|
|
54
|
+
"eslint-plugin-chai-friendly": "^0.4.1",
|
|
55
|
+
"husky": "^4.3.0",
|
|
56
|
+
"mocha": "^8.2.1",
|
|
48
57
|
"mocha-lcov-reporter": "^1.3.0",
|
|
49
|
-
"nyc": "^14.1.1"
|
|
58
|
+
"nyc": "^14.1.1",
|
|
59
|
+
"semantic-release": "^17.2.2",
|
|
60
|
+
"sinon": "^9.2.1",
|
|
61
|
+
"sinon-chai": "^3.5.0",
|
|
62
|
+
"ts-mocha": "^8.0.0",
|
|
63
|
+
"ts-node": "^9.0.0",
|
|
64
|
+
"typescript": "^4.0.5"
|
|
50
65
|
}
|
|
51
66
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["es2015", "es6", "es7", "es2017.object", "es2018.promise"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./lib",
|
|
9
|
+
"downlevelIteration": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"strictFunctionTypes": true,
|
|
13
|
+
"strictPropertyInitialization": true,
|
|
14
|
+
"noImplicitThis": true,
|
|
15
|
+
"alwaysStrict": true,
|
|
16
|
+
"allowJs": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noImplicitReturns": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true,
|
|
20
|
+
"moduleResolution": "node",
|
|
21
|
+
"baseUrl": "./",
|
|
22
|
+
"types": ["node", "mocha", "chai"],
|
|
23
|
+
"esModuleInterop": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["lib"]
|
|
26
|
+
}
|
package/.idea/aml-utils.iml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/aml-utils.iml" filepath="$PROJECT_DIR$/.idea/aml-utils.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
package/.idea/vcs.xml
DELETED
package/.idea/workspace.xml
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ChangeListManager">
|
|
4
|
-
<list default="true" id="13258785-846b-4fb0-8bed-0999c26076e5" name="Default Changelist" comment="">
|
|
5
|
-
<change beforePath="$PROJECT_DIR$/lib/validations.js" beforeDir="false" afterPath="$PROJECT_DIR$/lib/validations.js" afterDir="false" />
|
|
6
|
-
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
7
|
-
<change beforePath="$PROJECT_DIR$/test/validations.spec.js" beforeDir="false" afterPath="$PROJECT_DIR$/test/validations.spec.js" afterDir="false" />
|
|
8
|
-
</list>
|
|
9
|
-
<option name="SHOW_DIALOG" value="false" />
|
|
10
|
-
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
11
|
-
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
12
|
-
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
13
|
-
</component>
|
|
14
|
-
<component name="Git.Settings">
|
|
15
|
-
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
16
|
-
</component>
|
|
17
|
-
<component name="ProjectId" id="1cYJJDg3VaPA7J75A1iS6a3J7sb" />
|
|
18
|
-
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
|
19
|
-
<component name="ProjectViewState">
|
|
20
|
-
<option name="hideEmptyMiddlePackages" value="true" />
|
|
21
|
-
<option name="showExcludedFiles" value="true" />
|
|
22
|
-
<option name="showLibraryContents" value="true" />
|
|
23
|
-
</component>
|
|
24
|
-
<component name="PropertiesComponent">
|
|
25
|
-
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
26
|
-
<property name="WebServerToolWindowFactoryState" value="false" />
|
|
27
|
-
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
|
28
|
-
<property name="node.js.detected.package.eslint" value="true" />
|
|
29
|
-
<property name="node.js.path.for.package.eslint" value="project" />
|
|
30
|
-
<property name="node.js.selected.package.eslint" value="(autodetect)" />
|
|
31
|
-
<property name="nodejs_package_manager_path" value="npm" />
|
|
32
|
-
</component>
|
|
33
|
-
<component name="SvnConfiguration">
|
|
34
|
-
<configuration />
|
|
35
|
-
</component>
|
|
36
|
-
<component name="TaskManager">
|
|
37
|
-
<task active="true" id="Default" summary="Default task">
|
|
38
|
-
<changelist id="13258785-846b-4fb0-8bed-0999c26076e5" name="Default Changelist" comment="" />
|
|
39
|
-
<created>1590699519147</created>
|
|
40
|
-
<option name="number" value="Default" />
|
|
41
|
-
<option name="presentableId" value="Default" />
|
|
42
|
-
<updated>1590699519147</updated>
|
|
43
|
-
<workItem from="1590699522869" duration="144000" />
|
|
44
|
-
<workItem from="1590699690015" duration="407000" />
|
|
45
|
-
<workItem from="1590700324370" duration="1060000" />
|
|
46
|
-
</task>
|
|
47
|
-
<servers />
|
|
48
|
-
</component>
|
|
49
|
-
<component name="TypeScriptGeneratedFilesManager">
|
|
50
|
-
<option name="version" value="1" />
|
|
51
|
-
</component>
|
|
52
|
-
</project>
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
declare module '@ellipticltd/aml-utils';
|
package/index.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|