@ellipticltd/aml-utils 0.7.0 → 0.8.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.
Files changed (85) hide show
  1. package/.circleci/config.yml +37 -4
  2. package/.eslintrc +30 -6
  3. package/.huskyrc +5 -0
  4. package/.mocharc.json +3 -0
  5. package/.releaserc.json +18 -0
  6. package/README.md +39 -0
  7. package/commitlint.config.js +1 -0
  8. package/dist/errors/errors.d.ts +9 -0
  9. package/dist/errors/errors.js +42 -0
  10. package/dist/errors/errors.spec.d.ts +1 -0
  11. package/dist/errors/errors.spec.js +23 -0
  12. package/dist/file-parser/__tests/file-parser.spec.d.ts +1 -0
  13. package/dist/file-parser/__tests/file-parser.spec.js +113 -0
  14. package/dist/file-parser/__tests/parse-row.spec.d.ts +1 -0
  15. package/dist/file-parser/__tests/parse-row.spec.js +29 -0
  16. package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +1 -0
  17. package/dist/file-parser/__tests/sanitize-rows.spec.js +78 -0
  18. package/dist/file-parser/errors.d.ts +3 -0
  19. package/dist/file-parser/errors.js +11 -0
  20. package/dist/file-parser/file-parser.d.ts +8 -0
  21. package/dist/file-parser/file-parser.js +68 -0
  22. package/dist/file-parser/parse-row.d.ts +2 -0
  23. package/dist/file-parser/parse-row.js +39 -0
  24. package/dist/file-parser/sanitzeRows.d.ts +3 -0
  25. package/dist/file-parser/sanitzeRows.js +18 -0
  26. package/dist/formatting/formatting.d.ts +2 -0
  27. package/dist/formatting/formatting.js +17 -0
  28. package/dist/formatting/formatting.spec.d.ts +1 -0
  29. package/dist/formatting/formatting.spec.js +37 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.js +20 -0
  32. package/dist/middleware/middleware.d.ts +4 -0
  33. package/dist/middleware/middleware.js +22 -0
  34. package/dist/orm-helpers/ormHelpers.d.ts +1 -0
  35. package/dist/orm-helpers/ormHelpers.js +17 -0
  36. package/dist/orm-helpers/ormHelpers.spec.d.ts +1 -0
  37. package/dist/orm-helpers/ormHelpers.spec.js +38 -0
  38. package/dist/types/types.d.ts +17 -0
  39. package/dist/types/types.js +203 -0
  40. package/dist/validations/validations.d.ts +116 -0
  41. package/dist/validations/validations.js +296 -0
  42. package/dist/validations/validations.spec.d.ts +1 -0
  43. package/dist/validations/validations.spec.js +272 -0
  44. package/lib/errors/errors.spec.js +37 -0
  45. package/lib/file-parser/__tests/file-parser.spec.js +101 -0
  46. package/lib/file-parser/__tests/parse-row.spec.js +35 -0
  47. package/lib/file-parser/__tests/sanitize-rows.spec.js +88 -0
  48. package/lib/file-parser/errors.ts +7 -0
  49. package/lib/file-parser/file-parser.ts +84 -0
  50. package/lib/file-parser/parse-row.ts +52 -0
  51. package/lib/file-parser/sanitzeRows.ts +32 -0
  52. package/lib/formatting/formatting.spec.js +45 -0
  53. package/lib/index.ts +17 -0
  54. package/lib/{middleware.js → middleware/middleware.js} +1 -1
  55. package/lib/orm-helpers/ormHelpers.spec.js +41 -0
  56. package/lib/{types.js → types/types.js} +2 -2
  57. package/lib/{validations.js → validations/validations.js} +39 -7
  58. package/lib/validations/validations.spec.js +354 -0
  59. package/package.json +28 -13
  60. package/tsconfig.json +26 -0
  61. package/.nyc_output/0d2fdad3-7c58-4fdd-8d13-1bcb090f6cc6.json +0 -1
  62. package/.nyc_output/c8a4acec-3daa-459a-8aa3-cefb11e1430a.json +0 -1
  63. package/.nyc_output/dd0765ec-ad3f-4e3c-bbe6-12057d31a820.json +0 -1
  64. package/.nyc_output/ede345bb-a053-4be5-b26d-46cc26104776.json +0 -1
  65. package/.nyc_output/processinfo/0d2fdad3-7c58-4fdd-8d13-1bcb090f6cc6.json +0 -1
  66. package/.nyc_output/processinfo/c8a4acec-3daa-459a-8aa3-cefb11e1430a.json +0 -1
  67. package/.nyc_output/processinfo/dd0765ec-ad3f-4e3c-bbe6-12057d31a820.json +0 -1
  68. package/.nyc_output/processinfo/ede345bb-a053-4be5-b26d-46cc26104776.json +0 -1
  69. package/.nyc_output/processinfo/index.json +0 -1
  70. package/coverage/base.css +0 -224
  71. package/coverage/block-navigation.js +0 -79
  72. package/coverage/errors.js.html +0 -228
  73. package/coverage/formatting.js.html +0 -123
  74. package/coverage/index.html +0 -136
  75. package/coverage/ormHelpers.js.html +0 -123
  76. package/coverage/prettify.css +0 -1
  77. package/coverage/prettify.js +0 -2
  78. package/coverage/sort-arrow-sprite.png +0 -0
  79. package/coverage/sorter.js +0 -170
  80. package/coverage/validations.js.html +0 -882
  81. package/index.d.ts +0 -1
  82. package/index.js +0 -8
  83. /package/lib/{errors.js → errors/errors.js} +0 -0
  84. /package/lib/{formatting.js → formatting/formatting.js} +0 -0
  85. /package/lib/{ormHelpers.js → orm-helpers/ormHelpers.js} +0 -0
@@ -0,0 +1,101 @@
1
+ import sinon from 'sinon';
2
+ import { expect } from 'chai';
3
+ import parseFile from '../file-parser';
4
+ import * as sanitizeRows from '../sanitzeRows';
5
+ import * as parseRow from '../parse-row';
6
+
7
+ describe('file-parser', () => {
8
+ const dependencies = {
9
+ processRow: sinon.spy(),
10
+ };
11
+
12
+ const parsedRows = [];
13
+ const mockParseRow = sinon.stub(parseRow, 'default').returns(parsedRows);
14
+ const mockSanitizeRows = sinon.stub(sanitizeRows, 'default').returns([{}]);
15
+ const mockSetTimeout = sinon.stub(global, 'setTimeout').callsFake((callback) => callback());
16
+
17
+ beforeEach(() => {
18
+ sinon.resetHistory();
19
+ });
20
+
21
+ after(() => {
22
+ sinon.restore();
23
+ });
24
+
25
+ it('should call parseRow once per input new line', async () => {
26
+ const input = '\n';
27
+
28
+ await parseFile(input, 50, dependencies);
29
+
30
+ expect(mockParseRow).to.be.calledTwice;
31
+ });
32
+
33
+ it('should call pass parseRow result into sanitizeRows', async () => {
34
+ const input = '\n';
35
+
36
+ await parseFile(input, 50, dependencies);
37
+
38
+ expect(mockSanitizeRows).to.be.calledOnce;
39
+ expect(mockSanitizeRows).to.be.deep.calledWith([[], []], dependencies.processRow);
40
+ });
41
+
42
+ it('should throw error when number of rows is more than max rows', async () => {
43
+ const input = '\n';
44
+
45
+ mockSanitizeRows.returns(new Array(20));
46
+ try {
47
+ await parseFile(input, 10, dependencies);
48
+ expect(1).to.equal(2);
49
+ } catch (ex) {
50
+ expect(ex.name).to.equal('TooManyRowsError');
51
+ }
52
+ });
53
+
54
+ it('should throw error when no rows returned from sanitizeRows', async () => {
55
+ const input = '\n';
56
+
57
+ mockSanitizeRows.returns([]);
58
+ try {
59
+ await parseFile(input, 10, dependencies);
60
+ expect(1).to.equal(2);
61
+ } catch (ex) {
62
+ expect(ex.name).to.equal('Error');
63
+ }
64
+ });
65
+
66
+ it('should throw error an error when content is "invalidFileType"', async () => {
67
+ const input = 'invalidFileType';
68
+
69
+ mockSanitizeRows.returns([]);
70
+ try {
71
+ await parseFile(input, 10, dependencies);
72
+ expect(1).to.equal(2);
73
+ } catch (ex) {
74
+ expect(ex.message).to.equal('Invalid file type');
75
+ }
76
+ });
77
+
78
+ it('should call process row once per row in single timeout', async () => {
79
+ const input = '\n';
80
+
81
+ const fakeRows = (new Array(30)).fill({});
82
+ mockSanitizeRows.returns(fakeRows);
83
+
84
+ await parseFile(input, 70, dependencies);
85
+
86
+ expect(dependencies.processRow).to.be.callCount(30);
87
+ expect(mockSetTimeout).to.be.calledOnce;
88
+ });
89
+
90
+ it('should call process row once per row in two timeouts when more than 30 rows', async () => {
91
+ const input = '\n';
92
+
93
+ const fakeRows = (new Array(50)).fill({});
94
+ mockSanitizeRows.returns(fakeRows);
95
+
96
+ await parseFile(input, 70, dependencies);
97
+
98
+ expect(dependencies.processRow).to.be.callCount(50);
99
+ expect(mockSetTimeout).to.be.calledTwice;
100
+ });
101
+ });
@@ -0,0 +1,35 @@
1
+ import { expect } from 'chai';
2
+ import parseRow from '../parse-row';
3
+
4
+ describe('parse-row', () => {
5
+ it('should handle tabs', () => {
6
+ const input = 'asdas \t asdar \t aaaaa \t bbb bb';
7
+
8
+ const result = parseRow(input);
9
+ expect(result).to.have.length(4);
10
+ });
11
+
12
+ it('should handle comas', () => {
13
+ const input = 'asdas, asdar, aaaaa, bbb bb';
14
+
15
+ const result = parseRow(input);
16
+
17
+ expect(result).to.have.length(4);
18
+ });
19
+
20
+ it('should handle spaces', () => {
21
+ const input = 'asdas asdar aaaaa bbb bb';
22
+
23
+ const result = parseRow(input);
24
+
25
+ expect(result).to.have.length(4);
26
+ });
27
+
28
+ it('should handle spaces', () => {
29
+ const input = 'asdas asdar aaaaa bbb bb';
30
+
31
+ const result = parseRow(input);
32
+
33
+ expect(result).to.have.length(5);
34
+ });
35
+ });
@@ -0,0 +1,88 @@
1
+ import { expect } from 'chai';
2
+ import sinon from 'sinon';
3
+ import sanitizeRows from '../sanitzeRows';
4
+
5
+ describe('sanitize-rows', () => {
6
+ it('should remove empty rows at the start of the array', () => {
7
+ const input = [
8
+ ['', '', ''],
9
+ ['this', 'is', 'valid'],
10
+ ['this', 'is', 'valid'],
11
+ ];
12
+
13
+ const result = sanitizeRows(input, () => ({
14
+ isValid: true,
15
+ }));
16
+
17
+ expect(result).to.have.length(2);
18
+ });
19
+
20
+ it('should remove empty rows at the end of the array', () => {
21
+ const input = [
22
+ ['this', 'is', 'valid'],
23
+ ['this', 'is', 'valid'],
24
+ ['', '', ''],
25
+ ];
26
+
27
+ const result = sanitizeRows(input, () => ({
28
+ isValid: true,
29
+ }));
30
+
31
+ expect(result).to.have.length(2);
32
+ });
33
+
34
+ it('should remove empty rows at the start and end of the array', () => {
35
+ const input = [
36
+ ['', '', ''],
37
+ ['', '', ''],
38
+ ['', '', ''],
39
+ ['this', 'is', 'valid'],
40
+ ['this', 'is', 'valid'],
41
+ ['', '', ''],
42
+ ['', '', ''],
43
+ ['', '', ''],
44
+ ];
45
+
46
+ const result = sanitizeRows(input, () => ({
47
+ isValid: true,
48
+ }));
49
+
50
+ expect(result).to.have.length(2);
51
+ });
52
+
53
+ it('should remove the first row if it is not empty and not valid', () => {
54
+ const input = [
55
+ ['', '', ''],
56
+ ['this', 'is', 'invalid'],
57
+ ['this', 'is', 'valid'],
58
+ ['this', 'is', 'valid'],
59
+ ['', '', ''],
60
+ ['', '', ''],
61
+ ['', '', ''],
62
+ ];
63
+
64
+ const returnsFalseOnce = sinon.stub();
65
+ returnsFalseOnce.returns(true);
66
+ returnsFalseOnce.onFirstCall().returns(false);
67
+
68
+ const result = sanitizeRows(input, returnsFalseOnce);
69
+ expect(result).to.have.length(2);
70
+ });
71
+
72
+ it('should allow rows with some empty values', () => {
73
+ const input = [
74
+ ['this', 'is', 'invalid'],
75
+ ['this', 'is', 'valid'],
76
+ ['this', 'is', 'valid'],
77
+ ['valid', '', ''],
78
+ ['', '', ''],
79
+ ['', '', ''],
80
+ ];
81
+
82
+ const result = sanitizeRows(input, () => ({
83
+ isValid: true,
84
+ }));
85
+
86
+ expect(result).to.have.length(4);
87
+ });
88
+ });
@@ -0,0 +1,7 @@
1
+ // eslint-disable-next-line import/prefer-default-export
2
+ export class TooManyRowsError extends Error {
3
+ constructor() {
4
+ super('More than configured number of rows imported');
5
+ this.name = 'TooManyRowsError';
6
+ }
7
+ }
@@ -0,0 +1,84 @@
1
+ import parseRow from './parse-row';
2
+ import { TooManyRowsError } from './errors';
3
+ import sanitizeRows from './sanitzeRows';
4
+
5
+ export type ProcessingEntry = {
6
+ isValid: boolean,
7
+ };
8
+
9
+ type Dependencies<T extends ProcessingEntry> = {
10
+ processRow: () => T,
11
+ };
12
+
13
+ function chunk<T>(array: T[], size: number): T[][] {
14
+ if (!array.length) {
15
+ return [];
16
+ }
17
+ const head = array.slice(0, size);
18
+ const tail = array.slice(size);
19
+
20
+ return [head, ...chunk(tail, size)];
21
+ }
22
+
23
+ async function processChunk<T extends ProcessingEntry>(
24
+ parsedRows: string[][],
25
+ dependencies: Dependencies<T>,
26
+ ): Promise<T[]> {
27
+ const { processRow } = dependencies;
28
+ return new Promise(
29
+ (
30
+ resolve: (value: T[] | undefined) => void,
31
+ reject: (error: Error) => void,
32
+ ): void => {
33
+ setTimeout(
34
+ () => {
35
+ try {
36
+ const processedRows = parsedRows.map(processRow);
37
+ resolve(processedRows);
38
+ } catch (ex) {
39
+ reject(ex);
40
+ }
41
+ },
42
+ 0,
43
+ );
44
+ },
45
+ );
46
+ }
47
+
48
+ async function parseFile<T extends ProcessingEntry>(
49
+ fileContent: string,
50
+ maxRows: number,
51
+ dependencies: Dependencies<T>,
52
+ ): Promise<T[]> {
53
+ const { processRow } = dependencies;
54
+
55
+ if (fileContent === 'invalidFileType') {
56
+ throw Error('Invalid file type');
57
+ }
58
+
59
+ const rows = fileContent.split('\n');
60
+ const parsedRows = rows.map(parseRow);
61
+
62
+ const sanitizedRows = sanitizeRows(parsedRows, processRow);
63
+
64
+ if (sanitizedRows.length > maxRows) {
65
+ throw new TooManyRowsError();
66
+ }
67
+
68
+ if (sanitizedRows.length === 0) {
69
+ throw new Error('No rows');
70
+ }
71
+
72
+ const parsedRowChunks = chunk(sanitizedRows, 30);
73
+ let results: T[] = [];
74
+ // eslint-disable-next-line no-restricted-syntax
75
+ for (const currentRowChunk of parsedRowChunks) {
76
+ // eslint-disable-next-line no-await-in-loop
77
+ const chunkResult = await processChunk(currentRowChunk, dependencies);
78
+ results = results.concat(chunkResult);
79
+ }
80
+
81
+ return results;
82
+ }
83
+
84
+ export default parseFile;
@@ -0,0 +1,52 @@
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;
@@ -0,0 +1,32 @@
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;
@@ -0,0 +1,45 @@
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 ADDED
@@ -0,0 +1,17 @@
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,4 +1,4 @@
1
- const T = require('./types');
1
+ const T = require('../types/types');
2
2
 
3
3
  const ensureType = (type) => (req, res, next, id, name) => {
4
4
  let error;
@@ -0,0 +1,41 @@
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
+ });
@@ -2,9 +2,9 @@ const TC = require('type-check');
2
2
 
3
3
  const _ = require('lodash');
4
4
 
5
- const E = require('./errors');
5
+ const E = require('../errors/errors');
6
6
 
7
- const V = require('./validations');
7
+ const V = require('../validations/validations');
8
8
 
9
9
  const customTypes = {
10
10
  Integer: {
@@ -12,8 +12,7 @@ const addressValidator = require('wallet-address-validator');
12
12
  const zilUtils = require('@zilliqa-js/util');
13
13
  const web3 = require('web3-utils');
14
14
  const stellarSDK = require('stellar-sdk');
15
- const E = require('./errors');
16
-
15
+ const E = require('../errors/errors');
17
16
 
18
17
  const validations = {
19
18
  _validate(Err, pred, x, msg) {
@@ -115,6 +114,17 @@ const validations = {
115
114
  && (x != null ? x.length : undefined) <= 50
116
115
  );
117
116
  },
117
+ binanceCoin: {
118
+ isAddress(str) {
119
+ return /^(bnb)([a-z0-9]{39})$/.test(str);
120
+ },
121
+ isTxHash(str) {
122
+ if (!V.isHexadecimal(str)) {
123
+ return false;
124
+ }
125
+ return str.length === 64;
126
+ },
127
+ },
118
128
  bitcoin: {
119
129
  isAddress(str) {
120
130
  const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
@@ -219,6 +229,17 @@ const validations = {
219
229
  }
220
230
  },
221
231
  },
232
+ horizen: {
233
+ isAddress(str) {
234
+ return addressValidator.validate(str, 'ZEN');
235
+ },
236
+ isTxHash(str) {
237
+ if (!V.isHexadecimal(str)) {
238
+ return false;
239
+ }
240
+ return str.length === 64;
241
+ },
242
+ },
222
243
  litecoin: {
223
244
  isAddress(str) {
224
245
  return /^[3LM][a-km-zA-HJ-NP-Z1-9]{24,33}$|^ltc1[ac-hj-np-z02-9]{6,86}$|^LTC1[AC-HJ-NP-Z02-9]{6,86}$/.test(str);
@@ -241,17 +262,20 @@ const validations = {
241
262
  return str.length === 64;
242
263
  },
243
264
  },
244
- zilliqa: {
265
+ stellar: {
245
266
  isAddress(str) {
246
- return zilUtils.validation.isBech32(str);
267
+ return stellarSDK.StrKey.isValidEd25519PublicKey(str);
247
268
  },
248
269
  isTxHash(str) {
249
- return str.length === 66 && web3.isHexStrict(str);
270
+ if (!V.isHexadecimal(str)) {
271
+ return false;
272
+ }
273
+ return str.length === 64;
250
274
  },
251
275
  },
252
- stellar: {
276
+ zcash: {
253
277
  isAddress(str) {
254
- return stellarSDK.StrKey.isValidEd25519PublicKey(str);
278
+ return addressValidator.validate(str, 'ZEC');
255
279
  },
256
280
  isTxHash(str) {
257
281
  if (!V.isHexadecimal(str)) {
@@ -260,6 +284,14 @@ const validations = {
260
284
  return str.length === 64;
261
285
  },
262
286
  },
287
+ zilliqa: {
288
+ isAddress(str) {
289
+ return zilUtils.validation.isBech32(str);
290
+ },
291
+ isTxHash(str) {
292
+ return str.length === 66 && web3.isHexStrict(str);
293
+ },
294
+ },
263
295
  };
264
296
 
265
297
  Object.keys(V).forEach((k) => {