@ellipticltd/aml-utils 0.8.0-EN-2570.3 → 0.8.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.
Files changed (71) hide show
  1. package/.circleci/config.yml +4 -37
  2. package/.eslintrc +6 -30
  3. package/.idea/aml-utils.iml +8 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/misc.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/.idea/workspace.xml +52 -0
  9. package/README.md +0 -39
  10. package/index.d.ts +1 -0
  11. package/index.js +8 -0
  12. package/lib/{middleware/middleware.js → middleware.js} +1 -1
  13. package/lib/{types/types.js → types.js} +2 -2
  14. package/lib/{validations/validations.ts → validations.js} +55 -75
  15. package/package.json +13 -28
  16. package/.huskyrc +0 -5
  17. package/.mocharc.json +0 -3
  18. package/.releaserc.json +0 -18
  19. package/commitlint.config.js +0 -1
  20. package/dist/errors/errors.d.ts +0 -9
  21. package/dist/errors/errors.js +0 -42
  22. package/dist/errors/errors.spec.d.ts +0 -1
  23. package/dist/errors/errors.spec.js +0 -23
  24. package/dist/file-parser/__tests/file-parser.spec.d.ts +0 -1
  25. package/dist/file-parser/__tests/file-parser.spec.js +0 -113
  26. package/dist/file-parser/__tests/parse-row.spec.d.ts +0 -1
  27. package/dist/file-parser/__tests/parse-row.spec.js +0 -29
  28. package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +0 -1
  29. package/dist/file-parser/__tests/sanitize-rows.spec.js +0 -78
  30. package/dist/file-parser/errors.d.ts +0 -3
  31. package/dist/file-parser/errors.js +0 -11
  32. package/dist/file-parser/file-parser.d.ts +0 -8
  33. package/dist/file-parser/file-parser.js +0 -68
  34. package/dist/file-parser/parse-row.d.ts +0 -2
  35. package/dist/file-parser/parse-row.js +0 -39
  36. package/dist/file-parser/sanitzeRows.d.ts +0 -3
  37. package/dist/file-parser/sanitzeRows.js +0 -18
  38. package/dist/formatting/formatting.d.ts +0 -2
  39. package/dist/formatting/formatting.js +0 -17
  40. package/dist/formatting/formatting.spec.d.ts +0 -1
  41. package/dist/formatting/formatting.spec.js +0 -37
  42. package/dist/index.d.ts +0 -8
  43. package/dist/index.js +0 -20
  44. package/dist/middleware/middleware.d.ts +0 -4
  45. package/dist/middleware/middleware.js +0 -22
  46. package/dist/orm-helpers/ormHelpers.d.ts +0 -1
  47. package/dist/orm-helpers/ormHelpers.js +0 -17
  48. package/dist/orm-helpers/ormHelpers.spec.d.ts +0 -1
  49. package/dist/orm-helpers/ormHelpers.spec.js +0 -38
  50. package/dist/types/types.d.ts +0 -17
  51. package/dist/types/types.js +0 -203
  52. package/dist/validations/validations.d.ts +0 -5
  53. package/dist/validations/validations.js +0 -303
  54. package/dist/validations/validations.spec.d.ts +0 -1
  55. package/dist/validations/validations.spec.js +0 -276
  56. package/lib/errors/errors.spec.js +0 -37
  57. package/lib/file-parser/__tests/file-parser.spec.js +0 -101
  58. package/lib/file-parser/__tests/parse-row.spec.js +0 -35
  59. package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -88
  60. package/lib/file-parser/errors.ts +0 -7
  61. package/lib/file-parser/file-parser.ts +0 -84
  62. package/lib/file-parser/parse-row.ts +0 -52
  63. package/lib/file-parser/sanitzeRows.ts +0 -32
  64. package/lib/formatting/formatting.spec.js +0 -45
  65. package/lib/index.ts +0 -17
  66. package/lib/orm-helpers/ormHelpers.spec.js +0 -41
  67. package/lib/validations/validations.spec.js +0 -355
  68. package/tsconfig.json +0 -26
  69. /package/lib/{errors/errors.js → errors.js} +0 -0
  70. /package/lib/{formatting/formatting.js → formatting.js} +0 -0
  71. /package/lib/{orm-helpers/ormHelpers.js → ormHelpers.js} +0 -0
@@ -1,52 +0,0 @@
1
- import { pipe } from 'lodash/fp';
2
-
3
- const parseRow = (row: string): string[] => {
4
- const trySplitByTab = (line: string | string[]): string | string[] => {
5
- if (typeof line === 'string' && line.match('\t')) {
6
- return line.split('\t');
7
- }
8
- return line;
9
- };
10
-
11
- const trySplitByComa = (line: string | string[]): string | string[] => {
12
- if (typeof line === 'string' && line.match(',')) {
13
- return line.split(',');
14
- }
15
- return line;
16
- };
17
-
18
- const trySplitByMultipleSpaces = (line: string | string[]): string | string[] => {
19
- if (typeof line === 'string' && line.match(/ {3,}/)) {
20
- return line.split(/ {3,}/);
21
- }
22
- return line;
23
- };
24
-
25
- const trySplitBySpace = (line: string | string[]): string | string[] => {
26
- if (typeof line === 'string' && line.match(' ')) {
27
- return line.split(' ');
28
- }
29
- return line;
30
- };
31
-
32
- const trySplitByNothing = (line: string | string[]): string[] => {
33
- if (typeof line === 'string') {
34
- return [line];
35
- }
36
- return line;
37
- };
38
-
39
- const splitRow = pipe(
40
- trySplitByTab,
41
- trySplitByComa,
42
- trySplitByMultipleSpaces,
43
- trySplitBySpace,
44
- trySplitByNothing,
45
- );
46
-
47
- const cells = splitRow(row);
48
-
49
- return cells.map((c: string) => c.trim());
50
- };
51
-
52
- export default parseRow;
@@ -1,32 +0,0 @@
1
- import { ProcessingEntry } from './file-parser';
2
-
3
- const sensicalRowCheck = (cells: string[]): boolean => (
4
- cells.some((cell: string) => !!cell)
5
- );
6
-
7
- function sanitizeRows<T extends ProcessingEntry>(
8
- parsedRows: string[][],
9
- processRow: (row: string[]) => T,
10
- ): string[][] {
11
- const firstSensicalRowIndex = parsedRows
12
- .findIndex(sensicalRowCheck);
13
-
14
- const lastSensicalRowIndex = [...parsedRows]
15
- .reverse()
16
- .findIndex(sensicalRowCheck);
17
-
18
- const sanitizedRows = parsedRows
19
- .splice(
20
- firstSensicalRowIndex,
21
- parsedRows.length - firstSensicalRowIndex - lastSensicalRowIndex,
22
- );
23
-
24
- const firstRow = processRow(sanitizedRows[0]);
25
-
26
- if (firstRow.isValid) {
27
- return sanitizedRows;
28
- }
29
- return sanitizedRows.splice(1);
30
- }
31
-
32
- export default sanitizeRows;
@@ -1,45 +0,0 @@
1
- const chai = require('chai');
2
- const { sqlEscapeWildcard, rethrowError } = require('./formatting');
3
-
4
- const { expect } = chai;
5
-
6
- describe('formatting.sqlEscapeWildcard', () => {
7
- describe('when passed an empty string', () => {
8
- it('returns an empty string', () => sqlEscapeWildcard('').should.equal(''));
9
- });
10
- describe('when passed a string with no sql wildcards', () => {
11
- it('returns the same string', () => {
12
- const str = 'foo bar';
13
- return sqlEscapeWildcard(str).should.equal(str);
14
- });
15
- });
16
- return describe('when passed a string with sql wildcards', () => {
17
- it('returns the string with \\ % _ escaped', () => {
18
- const str = 'foo\\dfs_erwr%rewr';
19
- return sqlEscapeWildcard(str).should.equal('foo\\\\dfs\\_erwr\\%rewr');
20
- });
21
- });
22
- });
23
-
24
- describe('rethrowError', () => {
25
- it('returns an error when given a string', (
26
-
27
- ) => rethrowError('myFunc', { error: 'Oh dear, myFunc is broken' })
28
- .should.equal('myFunc - undefined: undefined - Oh dear, myFunc is broken'));
29
-
30
- it('returns an error when passed an error object', () => rethrowError('myFunc', {
31
- name: "I'm a teapot",
32
- statusCode: 418,
33
- error: "I'm a little teapot, short and stout",
34
- }).should.equal("myFunc - I'm a teapot: 418 - I'm a little teapot, short and stout"));
35
-
36
- it('accepts an array containing an error', () => {
37
- const thrownError = rethrowError('myFunc', {
38
- error: ["I'm a teapot", 418, "I'm a little teapot, short and stout"],
39
- });
40
-
41
- const expected = JSON.stringify('myFunc - undefined: undefined - \n[\n "I\'m a teapot",\n 418,\n "I\'m a little teapot, short and stout"\n]');
42
-
43
- expect(JSON.stringify(thrownError)).to.equal(expected);
44
- });
45
- });
package/lib/index.ts DELETED
@@ -1,17 +0,0 @@
1
- import types from './types/types';
2
- import validations from './validations/validations';
3
- import errors from './errors/errors';
4
- import formatting from './formatting/formatting';
5
- import middleware from './middleware/middleware';
6
- import ormHelpers from './orm-helpers/ormHelpers';
7
- import fileParser from './file-parser/file-parser';
8
-
9
- export {
10
- types,
11
- validations,
12
- errors,
13
- formatting,
14
- fileParser,
15
- middleware,
16
- ormHelpers,
17
- };
@@ -1,41 +0,0 @@
1
- const { includeNested } = require('./ormHelpers');
2
-
3
- describe('ormIncludeNested', () => {
4
- const orm = {
5
- a: 'a',
6
- b: 'b',
7
- c: 'c',
8
- d: 'd',
9
- };
10
-
11
- describe('when passed an empty object', () => {
12
- it('returns an empty array', () => includeNested(orm, {}).should.deep.equal([]));
13
- });
14
-
15
- describe('when passed an object with no inclusions', () => {
16
- it('returns an array of just the key', () => includeNested(orm, {
17
- a: {},
18
- }).should.deep.equal(['a']));
19
- });
20
-
21
- describe('when passed a hierarchy of inclusions', () => {
22
- it('should nest them in sequelize style', () => includeNested(orm, {
23
- a: {
24
- b: {
25
- c: {},
26
- d: {},
27
- },
28
- },
29
- }).should.deep.equal([
30
- {
31
- model: 'a',
32
- include: [
33
- {
34
- model: 'b',
35
- include: ['c', 'd'],
36
- },
37
- ],
38
- },
39
- ]));
40
- });
41
- });
@@ -1,355 +0,0 @@
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
- });
58
-
59
- describe('check', () => {
60
- describe('matches', () => {
61
- 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);
62
-
63
- it('should throw an error when passed two arrays that do not exactly match', () => {
64
- expect(() => validations.check.matches([1, 2, 3, 4], [1, 2, 3, 4, 5], 'Error message').to.throw('Error message'));
65
- });
66
- });
67
-
68
- describe('wasFound', () => {
69
- it('should return the string passed if this is not null', () => {
70
- expect(validations.check.wasFound()('string')).to.equal('string');
71
- });
72
- it('should throw an error if the item is null', () => {
73
- expect(() => validations.check.wasFound('no value')()).to.throw('Unknown no value');
74
- });
75
- });
76
-
77
- describe('wasCreated', () => {
78
- it('should return the array passed if it is not empty', () => {
79
- expect(validations.check.wasCreated()([1, 2, 3])).to.eql([1, 2, 3]);
80
- });
81
-
82
- it('should throw an error if the array is empty', () => {
83
- expect(() => validations.check.wasCreated('Oh no! No array!')([])).to.throw('Oh no! No array!');
84
- });
85
- });
86
-
87
- describe('isTrue', () => {
88
- const count = 2;
89
-
90
- it('should return true when the first arg is truthy', () => {
91
- assert(validations.check.isTrue(count === 2, 'Count equals 2'), 'isTrue should be false');
92
- });
93
-
94
- it('should throw an error when the first arg is falsy', () => {
95
- expect(() => validations.check.isTrue(count <= 1, 'Count is greater than 1')).to.throw('Count is greater than 1');
96
- });
97
- });
98
-
99
- describe('isFalse', () => {
100
- const count = 2;
101
-
102
- it('should return true when the first arg is falsy', () => {
103
- assert(validations.check.isFalse(count === 3, 'Count should not equal 3'), 'isFalse should be true');
104
- });
105
-
106
- it('should throw an error when the first arg is truthy', () => {
107
- expect(() => validations.check.isFalse(count > 1, 'Count should be greater than 1')).to.throw('Count should be greater than 1');
108
- });
109
- });
110
-
111
- describe('isCustomerReference', () => {
112
- it('should return true if the string is longer than 0 and less than or equal to 100 characters', () => {
113
- assert(validations.isCustomerReference('1'), 'isCustomerReference fails when the string length is 1');
114
- 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');
115
- });
116
-
117
- it('should return false when passed an empty string or one longer than 100 characters, or a non-string', () => {
118
- assert(!validations.isCustomerReference(''), 'isCustomerReference passes when passed an empty string');
119
- 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');
120
- assert(!validations.isCustomerReference(['array']), 'isCustomerReference passes when passed a non-string');
121
- });
122
- });
123
-
124
- describe('isCustomerLabelName', () => {
125
- it('should return true if the string is longer than 0 and less than or equal to 50 characters', () => {
126
- assert(validations.isCustomerLabelName('1'), 'isCustomerLabelName fails when the string length is 1');
127
- assert(validations.isCustomerLabelName('William Shakespeare was poet, playwright and actor'), 'isCustomerLabelName fails when the string length is 50');
128
- });
129
-
130
- it('should return false when passed an empty string or one longer than 50 characters, or a non-string', () => {
131
- assert(!validations.isCustomerLabelName(''), 'isCustomerLabelName passes when passed an empty string');
132
- 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');
133
- assert(!validations.isCustomerLabelName(['array']), 'isCustomerLabelName passes when passed a non-string');
134
- });
135
- });
136
- });
137
-
138
- describe('BCH', () => {
139
- describe('isAddress', () => {
140
- it('should correctly validate valid BCH addresses', () => validations.bitcoinCash.isAddress('bitcoincash:qrrfmt57avxfd2476gqxqq54djtcvjuzjc2qtsrzcw').should.be.true
141
- && validations.bitcoinCash.isAddress('qqrxa0h9jqnc7v4wmj9ysetsp3y7w9l36u8gnnjulq').should.be.true);
142
-
143
- it('should correctly validate an incorrect BCH address', () => validations.bitcoinCash.isAddress('qqrxa0h9jqnc7v4wmj3y7w9l36u8gnnjulq').should.be.false);
144
- });
145
-
146
- describe('isTxHash', () => {
147
- it('should correctly validate a valid BCH hash', () => validations.bitcoinCash.isTxHash('a32c4d2f9f2e322f19867dbacb7609a1be63c914b8f41775082b50d3ee1a0ce6').should.be.true);
148
-
149
- it('should correctly validate an incorrect BCH hash', () => validations.bitcoinCash.isTxHash('cd1bdc201022ca9386d8757b1c49ecc6ee3769cad2d42ab6e7f9e7bd831').should.be.false);
150
-
151
- it('should return false when passed a non-hex string', () => validations.bitcoinCash.isTxHash('Not a hex string!').should.be.false);
152
- });
153
- });
154
-
155
- describe('BNB', () => {
156
- describe('isAddress', () => {
157
- it('should correctly validate valid BNB addresses', () => validations.binanceCoin.isAddress('bnb1z35wusfv8twfele77vddclka9z84ugywug48gn').should.be.true);
158
-
159
- it('should correctly validate an incorrect BNB address', () => validations.binanceCoin.isAddress('bnb1z35wusfv8twfele77vddclka9z84ugywug48gn1').should.be.false);
160
- });
161
-
162
- describe('isTxHash', () => {
163
- it('should correctly validate a valid BNB hash', () => validations.binanceCoin.isTxHash('E68C2D178F989DE296FA1B513D1AA138B234C436B52E0D755C6664A70F7EEF7B').should.be.true);
164
-
165
- it('should correctly validate an incorrect BNB hash', () => validations.binanceCoin.isTxHash('E68C2D178F989DE296FA1B513D1AA138B234C436B52E0D755C6664A70F7EEF7B1').should.be.false);
166
-
167
- it('should return false when passed a non-hex string', () => validations.binanceCoin.isTxHash('Not a hex string!').should.be.false);
168
- });
169
- });
170
-
171
- describe('BTC', () => {
172
- describe('isAddress', () => {
173
- it('should correctly validate a valid BTC address', () => validations.bitcoin.isAddress('1LFnX5KT4CMKud7KB9xaXFZFkD3H8bUD16').should.be.true);
174
-
175
- it('should correctly validate an incorrect BTC address', () => validations.bitcoin.isAddress('1LFnX5KT4CMKud7KB9xaXFZFkD3H8b').should.be.false);
176
- });
177
-
178
- describe('isBech32Address', () => {
179
- it('should correctly validate a Bech32 address', () => validations.bitcoin.isBech32Address('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.true);
180
- it('should correctly validate an invalide Bech32 address', () => validations.bitcoin.isBech32Address('4ef47f6eb681d5d9fa2f7e16336cd629303c635e8da51e425b76088be9c8744c').should.be.false);
181
- });
182
-
183
- describe('isHDPublicKey', () => {
184
- it('should return true when passed an HD public key', () => validations.bitcoin.isHDPublicKey('xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi').should.be.true);
185
- it('should return false when not passed an HD public key', () => validations.bitcoin.isHDPublicKey('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.false);
186
- });
187
-
188
- describe('isPublicKey', () => {
189
- it('should return true when passed a public key', () => validations.bitcoin.isPublicKey('046c04c02f1138f440e8c5e9099db938bfba93d0389528bb7f6bf423ae203a2edcfba133f0409023d7ea13ac01c5aeedaf0bbfbeb8b82e9b48410d93a296da5b0c').should.be.true);
190
- it('should return false when not passed a public key', () => validations.bitcoin.isPublicKey('1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm').should.be.false);
191
- });
192
-
193
- describe('isTxHash', () => {
194
- it('should correctly validate a valid BTC hash', () => validations.bitcoin.isTxHash('835346f3ea00a23df60ca5dc24afce67810c792ac4505e544410d4b19e7c95a0').should.be.true);
195
- it('should correctly validate an incorrect BTC hash', () => validations.bitcoin.isTxHash('835346f3ea00a23df60caafce67810c792ac4505e544410d4b19e7c95a0').should.be.false);
196
- it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxHex('Definitely not a hex string').should.be.false);
197
- });
198
-
199
- describe('isTxHex', () => {
200
- const hex = '0100000002d8c8df6a6fdd2addaf589a83d860f18b44872d13ee6ec3526b2b470d42a96d4d000000008b483045022100b31557e47191936cb14e013fb421b1860b5e4fd5d2bc5ec1938f4ffb1651dc8902202661c2920771fd29dd91cd4100cefb971269836da4914d970d333861819265ba014104c54f8ea9507f31a05ae325616e3024bd9878cb0a5dff780444002d731577be4e2e69c663ff2da922902a4454841aa1754c1b6292ad7d317150308d8cce0ad7abffffffff2ab3fa4f68a512266134085d3260b94d3b6cfd351450cff021c045a69ba120b2000000008b4830450220230110bc99ef311f1f8bda9d0d968bfe5dfa4af171adbef9ef71678d658823bf022100f956d4fcfa0995a578d84e7e913f9bb1cf5b5be1440bcede07bce9cd5b38115d014104c6ec27cffce0823c3fecb162dbd576c88dd7cda0b7b32b0961188a392b488c94ca174d833ee6a9b71c0996620ae71e799fc7c77901db147fa7d97732e49c8226ffffffff02c0175302000000001976a914a3d89c53bb956f08917b44d113c6b2bcbe0c29b788acc01c3d09000000001976a91408338e1d5e26db3fce21b011795b1c3c8a5a5d0788ac00000000';
201
- it('should return true if passed a hex string Tx hash', () => validations.bitcoin.isTxHex(hex).should.be.true);
202
- it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxHex('definitelyNotAHexString').should.be.false);
203
- 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);
204
- });
205
-
206
- describe('isHDPath', () => {
207
- it('should return true when passed a valid HDPrivateKey path', () => validations.bitcoin.isHDPath('xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi'));
208
- it('should return false when passed a string that is not a valid HDPrivateKey path', () => validations.bitcoin.isHDPath('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq').should.be.false);
209
- });
210
-
211
- describe('isScriptHex', () => {
212
- it('should return true when passed a script hex', () => validations.bitcoin.isScriptHex('01000000011e2e8cfdf21d68f90974cd557a30c11894cc8cfec5cd5330e41846c2c84566bd000000006b4830450221009f61f453f44e807fdc538ca21710393d34005dd5709dabd8b6b9ccf09ea0b36a0220420d91a33f43d7b979471220e12cd1025975bd2e6c0bf2a14eb65ad89d578104012102de8f92034b9b3c956c1896d23a628537561e29faa772438aac2265c91ede6519ffffffff0118566202000000001976a914b27f04e510293c3e530e7b7bdf71f59118030e1e88ac00000000').should.be.true);
213
- it('should return false if the string passed is not a hex string', () => validations.bitcoin.isScriptHex('definitelyNotAHexString').should.be.false);
214
- 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);
215
- });
216
-
217
- describe('isTxSignature', () => {
218
- it('should return true when passed a tx hash that includes a signature', () => validations.bitcoin.isTxSignature('304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d1090db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501').should.be.true);
219
- it('should return false when passed a tx hash that does not include a signature', () => validations.bitcoin.isTxSignature('f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6').should.be.false);
220
- it('should return false if the string passed is not a hex string', () => validations.bitcoin.isTxSignature('definitelyNotAHexString').should.be.false);
221
- });
222
-
223
- describe('isBlockHeight', () => {
224
- it('should return true when passed a value greater than or equal to 0', () => validations.bitcoin.isBlockHeight(986789).should.be.true
225
- && validations.bitcoin.isBlockHeight('987654').should.be.true);
226
- it('should return false when passed a value that is not greater than or equal to 0', () => validations.bitcoin.isBlockHeight(null).should.be.false
227
- && validations.bitcoin.isBlockHeight('string').should.be.false);
228
- });
229
- });
230
-
231
- describe('ETH', () => {
232
- describe('isAddress', () => {
233
- it('should return true if the address evaluates as a web3 address', () => validations.ethereum.isAddress('0xa6Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.true);
234
- it('should return false if the address does not evaluate to a web3 address', () => validations.ethereum.isAddress('Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.false);
235
- });
236
-
237
- describe('isBlockHash', () => {
238
- it('should return true when given a valid hash', () => validations.ethereum.isBlockHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.true);
239
- it('should return false when given an vinalid hash', () => validations.ethereum.isBlockHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489eb0e').should.be.false);
240
- });
241
-
242
- describe('isTxHash', () => {
243
- it('should correctly validate a valid ETH hash', () => validations.ethereum.isTxHash('0xec6491abd46a1a9a71b78f4b84d96fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.true);
244
-
245
- it('should correctly validate an incorrect ETH hash', () => validations.ethereum.isTxHash('0xec6491abd46a1a9a71b7896fd49525aa4f66c8d8c3588c489f2f88eb0e').should.be.false);
246
- });
247
-
248
- describe('isAddressCode', () => {
249
- it('should return true if the string is a hex address', () => validations.ethereum.isAddressCode('0xa6Bc4b3fe7F2756124d30D896Fe4457711e9d214').should.be.true);
250
- it('should return false if the string is not a hex address', () => validations.ethereum.isAddressCode('0xa6Bc4b3fe7F27yu124d30D896Fe4457711e9d214').should.be.false);
251
- });
252
-
253
- describe('isValidWeiAmount', () => {
254
- it('should return true when passed an amount that evaluates to wei', () => validations.ethereum.isValidWeiAmount('7000000000000000').should.be.true);
255
- it('should return false when passed an amount that is not valid in wei', () => validations.ethereum.isValidWeiAmount(7000000000000000).should.be.false
256
- && validations.ethereum.isValidWeiAmount('1000.00').should.be.false);
257
- });
258
- });
259
-
260
- describe('LTC', () => {
261
- describe('isAddress', () => {
262
- it('should correctly validate valid LTC addresses', () => validations.litecoin.isAddress('LMR7przNNMS3GpaD6Ygq64NxbsJsZAqGgM').should.be.true);
263
-
264
- it('should correctly validate an incorrect LTC address', () => validations.litecoin.isAddress('t1t8BzkNb8d98o8kpbwrjtUjMX3GMF').should.be.false);
265
- });
266
-
267
- describe('isTxHash', () => {
268
- it('should correctly validate a valid LTC hash', () => validations.litecoin.isTxHash('b0b858b34675cc8f851e6a2174295ada574837422538efe9ca83ef405d2faf29').should.be.true);
269
-
270
- it('should correctly validate an incorrect LTC hash', () => validations.litecoin.isTxHash('b0b858b34675cc8f851e6a2295ada574837422538efe9ca83ef405d2faf29').should.be.false);
271
-
272
- it('should return false when passed a non-hex string', () => validations.litecoin.isTxHash('Not a hex code here').should.be.false);
273
- });
274
- });
275
-
276
- describe('XLM', () => {
277
- describe('isAddress', () => {
278
- it('should correctly validate valid XLM addresses', () => validations.stellar.isAddress('GBH4TZYZ4IRCPO44CBOLFUHULU2WGALXTAVESQA6432MBJMABBB4GIYI').should.be.true);
279
-
280
- it('should correctly validate an incorrect XLM address', () => validations.stellar.isAddress('GBH4TZYZ4IRCPO44CAAAAAAULU2WGALXTAVESQA6432MBJMABBB4GIYI').should.be.false);
281
- });
282
-
283
- describe('isTxHash', () => {
284
- it('should correctly validate a valid XLM hash', () => validations.stellar.isTxHash('dcf208070966a0f04dbff0be6abe5bc7ea2d77f16167e89e1869a8efc68ebe44').should.be.true);
285
-
286
- it('should correctly validate an incorrect XLM hash', () => validations.stellar.isTxHash('8ee1f64137b12d07f8d2ddd3460d78ecbe37ba671aa4e54af34de935cc2bba2ca').should.be.false);
287
-
288
- it('should return false when passed a non-hex string', () => validations.stellar.isTxHash('Yet again this is not a hex string').should.be.false);
289
- });
290
- });
291
-
292
- describe('XRP', () => {
293
- describe('isAddress', () => {
294
- it('should correctly validate valid XRP addresses', () => validations.ripple.isAddress('rDV3RhpWznRCmtpD17RNxg6t4Hg8NPV8mF').should.be.true);
295
-
296
- it('should correctly validate an incorrect XRP address', () => validations.ripple.isAddress('rDV3RhpWznRCmtpD17RNxg0t4Hg8NPV8mF').should.be.false);
297
- });
298
-
299
- describe('isTxHash', () => {
300
- it('should correctly validate a valid XRP hash', () => validations.ripple.isTxHash('C6593DD2A32ED5120DF1FE80665B84A9CCAF06ADDC2EF89F720CBAC3E8069C0E').should.be.true);
301
-
302
- it('should correctly validate an incorrect XRP hash', () => validations.ripple.isTxHash('C6593DD2A32ED5120DF1FE84A9CCAF06ADDC2EF89F720CBAC3E8069C0E').should.be.false);
303
-
304
- it('should return false when passed a non-hex string', () => validations.ripple.isTxHash('Yet again this is not a hex string').should.be.false);
305
- });
306
- });
307
-
308
- describe('ZEC', () => {
309
- describe('isAddress', () => {
310
- it('should correctly validate valid ZEC addresses', () => validations.zcash.isAddress('t1Jxptj7GnXQRsLNH5wWnDrGwEipEB3aZtf').should.be.true);
311
-
312
- it('should correctly validate an incorrect ZEC address', () => validations.zcash.isAddress('t1Jxptj7GnXQRsLNH5wWnDrGwEipEB3aZtf1').should.be.false);
313
- });
314
-
315
- describe('isTxHash', () => {
316
- it('should correctly validate a valid ZEC hash', () => validations.zcash.isTxHash('715c23949b85581de432f174a9e7f4d3f9e74b008064e2c68e7a52b1ec38e961').should.be.true);
317
-
318
- it('should correctly validate an incorrect ZEC hash', () => validations.zcash.isTxHash('715c23949b85581de432f174a9e7f4d3f9e74b008064e2c68e7a52b1ec38e9611').should.be.false);
319
-
320
- it('should return false when passed a non-hex string', () => validations.zcash.isTxHash('Yet again this is not a hex string').should.be.false);
321
- });
322
- });
323
-
324
- describe('ZEN', () => {
325
- describe('isAddress', () => {
326
- it('should correctly validate valid ZEN addresses', () => validations.horizen.isAddress('znUovxhrE91tep6D7YtgSc3XJZoYQLVDwVn').should.be.true);
327
-
328
- it('should correctly validate an incorrect ZEN address', () => validations.horizen.isAddress('znUovxhrE91tep6D7YtgSc3XJZoYQLVDwVn1').should.be.false);
329
- });
330
-
331
- describe('isTxHash', () => {
332
- it('should correctly validate a valid ZEN hash', () => validations.horizen.isTxHash('e5d31deb3fee023758f0b79d06489df975fce9aa53351b9b5c8491e4c33c74b7').should.be.true);
333
-
334
- it('should correctly validate an incorrect ZEN hash', () => validations.horizen.isTxHash('e5d31deb3fee023758f0b79d06489df975fce9aa53351b9b5c8491e4c33c74b71').should.be.false);
335
-
336
- it('should return false when passed a non-hex string', () => validations.horizen.isTxHash('Yet again this is not a hex string').should.be.false);
337
- });
338
- });
339
-
340
- describe('ZIL', () => {
341
- describe('isAddress', () => {
342
- it('should correctly validate valid ZIL addresses', () => validations.zilliqa.isAddress('zil1tw5rpejf96e76ty93l7c3dn0g79h2qhhdm28a4').should.be.true);
343
-
344
- it('should correctly validate an incorrect ZIL address', () => validations.zilliqa.isAddress('0x14456246cc53d31f0a2EB00FA0248F7aEbD3fa8').should.be.false);
345
- });
346
-
347
- describe('isTxHash', () => {
348
- it('should correctly validate a valid ZIL hash', () => validations.zilliqa.isTxHash('0xb9a04481c546258e339f8ce4cccdee3f179cc37a8f099f0608baf39e0a819f75').should.be.true);
349
-
350
- it('should correctly validate an incorrect ZIL hash', () => validations.zilliqa.isTxHash('0xb9a04481c546258e339f8ce4cccdee3f179cc37a8f099f0608baf39e0a819f7').should.be.false);
351
-
352
- it('should return false when passed a non-hex string', () => validations.zilliqa.isTxHash('Yet again this is not a hex string').should.be.false);
353
- });
354
- });
355
- });
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
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
- }
File without changes
File without changes