@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.
- package/.circleci/config.yml +4 -37
- package/.eslintrc +6 -30
- package/.idea/aml-utils.iml +8 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +52 -0
- package/README.md +0 -39
- package/index.d.ts +1 -0
- package/index.js +8 -0
- package/lib/{middleware/middleware.js → middleware.js} +1 -1
- package/lib/{types/types.js → types.js} +2 -2
- package/lib/{validations/validations.ts → validations.js} +55 -75
- package/package.json +13 -28
- package/.huskyrc +0 -5
- package/.mocharc.json +0 -3
- package/.releaserc.json +0 -18
- package/commitlint.config.js +0 -1
- package/dist/errors/errors.d.ts +0 -9
- package/dist/errors/errors.js +0 -42
- package/dist/errors/errors.spec.d.ts +0 -1
- package/dist/errors/errors.spec.js +0 -23
- package/dist/file-parser/__tests/file-parser.spec.d.ts +0 -1
- package/dist/file-parser/__tests/file-parser.spec.js +0 -113
- package/dist/file-parser/__tests/parse-row.spec.d.ts +0 -1
- package/dist/file-parser/__tests/parse-row.spec.js +0 -29
- package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +0 -1
- package/dist/file-parser/__tests/sanitize-rows.spec.js +0 -78
- package/dist/file-parser/errors.d.ts +0 -3
- package/dist/file-parser/errors.js +0 -11
- package/dist/file-parser/file-parser.d.ts +0 -8
- package/dist/file-parser/file-parser.js +0 -68
- package/dist/file-parser/parse-row.d.ts +0 -2
- package/dist/file-parser/parse-row.js +0 -39
- package/dist/file-parser/sanitzeRows.d.ts +0 -3
- package/dist/file-parser/sanitzeRows.js +0 -18
- package/dist/formatting/formatting.d.ts +0 -2
- package/dist/formatting/formatting.js +0 -17
- package/dist/formatting/formatting.spec.d.ts +0 -1
- package/dist/formatting/formatting.spec.js +0 -37
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -20
- package/dist/middleware/middleware.d.ts +0 -4
- package/dist/middleware/middleware.js +0 -22
- package/dist/orm-helpers/ormHelpers.d.ts +0 -1
- package/dist/orm-helpers/ormHelpers.js +0 -17
- package/dist/orm-helpers/ormHelpers.spec.d.ts +0 -1
- package/dist/orm-helpers/ormHelpers.spec.js +0 -38
- package/dist/types/types.d.ts +0 -17
- package/dist/types/types.js +0 -203
- package/dist/validations/validations.d.ts +0 -5
- package/dist/validations/validations.js +0 -303
- package/dist/validations/validations.spec.d.ts +0 -1
- package/dist/validations/validations.spec.js +0 -276
- package/lib/errors/errors.spec.js +0 -37
- package/lib/file-parser/__tests/file-parser.spec.js +0 -101
- package/lib/file-parser/__tests/parse-row.spec.js +0 -35
- package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -88
- package/lib/file-parser/errors.ts +0 -7
- package/lib/file-parser/file-parser.ts +0 -84
- package/lib/file-parser/parse-row.ts +0 -52
- package/lib/file-parser/sanitzeRows.ts +0 -32
- package/lib/formatting/formatting.spec.js +0 -45
- package/lib/index.ts +0 -17
- package/lib/orm-helpers/ormHelpers.spec.js +0 -41
- package/lib/validations/validations.spec.js +0 -355
- package/tsconfig.json +0 -26
- /package/lib/{errors/errors.js → errors.js} +0 -0
- /package/lib/{formatting/formatting.js → formatting.js} +0 -0
- /package/lib/{orm-helpers/ormHelpers.js → ormHelpers.js} +0 -0
package/.circleci/config.yml
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
version: 2.1
|
|
2
2
|
|
|
3
3
|
executors:
|
|
4
|
-
node-
|
|
4
|
+
node-8_4:
|
|
5
5
|
docker:
|
|
6
|
-
- image: circleci/node:
|
|
6
|
+
- image: circleci/node:8.4.0
|
|
7
7
|
working_directory: /tmp/workspace
|
|
8
8
|
|
|
9
9
|
jobs:
|
|
10
10
|
install:
|
|
11
|
-
executor: node-
|
|
11
|
+
executor: node-8_4
|
|
12
12
|
steps:
|
|
13
13
|
- checkout
|
|
14
14
|
- restore_cache:
|
|
@@ -28,7 +28,7 @@ jobs:
|
|
|
28
28
|
- workspace
|
|
29
29
|
|
|
30
30
|
unit_test:
|
|
31
|
-
executor: node-
|
|
31
|
+
executor: node-8_4
|
|
32
32
|
steps:
|
|
33
33
|
- attach_workspace:
|
|
34
34
|
at: /tmp
|
|
@@ -38,27 +38,6 @@ jobs:
|
|
|
38
38
|
- store_artifacts:
|
|
39
39
|
path: coverage
|
|
40
40
|
|
|
41
|
-
lint:
|
|
42
|
-
executor: node-12
|
|
43
|
-
steps:
|
|
44
|
-
- attach_workspace:
|
|
45
|
-
at: /tmp
|
|
46
|
-
- run:
|
|
47
|
-
name: lint
|
|
48
|
-
command: npm run lint
|
|
49
|
-
|
|
50
|
-
semantic_release:
|
|
51
|
-
executor: node-12
|
|
52
|
-
steps:
|
|
53
|
-
- checkout
|
|
54
|
-
- attach_workspace:
|
|
55
|
-
at: /tmp
|
|
56
|
-
- add_ssh_keys:
|
|
57
|
-
fingerprints:
|
|
58
|
-
- "14:c6:29:a4:9e:45:36:d2:0e:e9:be:41:35:d7:06:23"
|
|
59
|
-
- run:
|
|
60
|
-
command: npx semantic-release
|
|
61
|
-
|
|
62
41
|
workflows:
|
|
63
42
|
version: 2.1
|
|
64
43
|
build-test-deploy:
|
|
@@ -68,15 +47,3 @@ workflows:
|
|
|
68
47
|
- unit_test:
|
|
69
48
|
requires:
|
|
70
49
|
- install
|
|
71
|
-
|
|
72
|
-
- lint:
|
|
73
|
-
requires:
|
|
74
|
-
- install
|
|
75
|
-
|
|
76
|
-
- semantic_release:
|
|
77
|
-
context: npm
|
|
78
|
-
requires:
|
|
79
|
-
- lint
|
|
80
|
-
- unit_test
|
|
81
|
-
|
|
82
|
-
|
package/.eslintrc
CHANGED
|
@@ -1,44 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": [
|
|
2
|
+
"extends": [
|
|
3
|
+
"airbnb"
|
|
4
|
+
],
|
|
3
5
|
"overrides": [
|
|
4
6
|
{
|
|
5
7
|
"files": [
|
|
6
|
-
"*.
|
|
7
|
-
],
|
|
8
|
-
"parser": "@typescript-eslint/parser",
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"project": "tsconfig.json"
|
|
11
|
-
},
|
|
12
|
-
"rules": {
|
|
13
|
-
"no-unused-vars": 0
|
|
14
|
-
// annoyingly this must be switched off
|
|
15
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/46
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"files": [
|
|
20
|
-
"*.spec.js"
|
|
8
|
+
"*.spec.js",
|
|
21
9
|
],
|
|
22
10
|
"env": {
|
|
23
11
|
"mocha": true
|
|
24
|
-
}
|
|
25
|
-
"rules": {
|
|
26
|
-
"no-unused-expressions": 0,
|
|
27
|
-
"chai-friendly/no-unused-expressions": 2
|
|
28
|
-
},
|
|
29
|
-
"plugins": [
|
|
30
|
-
"chai-friendly"
|
|
31
|
-
]
|
|
12
|
+
}
|
|
32
13
|
}
|
|
33
14
|
],
|
|
34
15
|
"rules": {
|
|
35
16
|
"no-underscore-dangle": 0,
|
|
36
17
|
"prefer-object-spread": 0,
|
|
37
18
|
"new-parens": 0
|
|
38
|
-
},
|
|
39
|
-
"settings": {
|
|
40
|
-
"import/resolver": {
|
|
41
|
-
"typescript": {}
|
|
42
|
-
}
|
|
43
19
|
}
|
|
44
|
-
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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/README.md
CHANGED
|
@@ -6,42 +6,3 @@ This is a library that contains a set of utilities used by aml-api. In particula
|
|
|
6
6
|
- Formatting functions (sql escaping)
|
|
7
7
|
- Validator functions, also used by swagger node middleware. E.g. Bitcoin and Ethereum addresses validators
|
|
8
8
|
- Express middlewares to validate params types
|
|
9
|
-
- An async CSV file parser
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Prereqs
|
|
13
|
-
-------
|
|
14
|
-
|
|
15
|
-
1. Correct version of node (use [nvm](https://github.com/creationix/nvm)).
|
|
16
|
-
|
|
17
|
-
Development
|
|
18
|
-
-----------
|
|
19
|
-
|
|
20
|
-
`nvm use` ensures you are running the correct version of node.js.
|
|
21
|
-
|
|
22
|
-
`npm i` installs your dependencies.
|
|
23
|
-
|
|
24
|
-
`npm run build:dev`:
|
|
25
|
-
- starts webpack on watch mode, recompiling any changes made to the code
|
|
26
|
-
|
|
27
|
-
To test your changes locally go to the repo you are working on's package.json and replace:
|
|
28
|
-
```
|
|
29
|
-
@ellipticltd/aml-utils: "*.*.*"
|
|
30
|
-
```
|
|
31
|
-
with
|
|
32
|
-
```
|
|
33
|
-
@ellipticltd/aml-utils: "file:../front-end-component-kit"
|
|
34
|
-
```
|
|
35
|
-
(if you repositories are in the same directory).
|
|
36
|
-
|
|
37
|
-
Commiting
|
|
38
|
-
-----------
|
|
39
|
-
|
|
40
|
-
This repository uses [Semantic release](https://semantic-release.gitbook.io/) for version publishing. To create a new version of the package simply push to bitbucket and CircleCI will create a new version. No change to this repo's package.json is required.
|
|
41
|
-
|
|
42
|
-
To work out what the next version of package should be a git commit linter is used. This is enforced by Husky and only commits with the following syntax can be [used](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-angular).
|
|
43
|
-
|
|
44
|
-
Setting up Semantic release
|
|
45
|
-
-----------
|
|
46
|
-
|
|
47
|
-
This [article](https://circleci.com/docs/2.0/gh-bb-integration/#creating-a-bitbucket-user-key) explains the integration between Bitbucket and CirlceCI. An NPM token also needs to be provided for the write access to the npm package
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@ellipticltd/aml-utils';
|
package/index.js
ADDED
|
@@ -2,9 +2,9 @@ const TC = require('type-check');
|
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
4
|
|
|
5
|
-
const E = require('
|
|
5
|
+
const E = require('./errors');
|
|
6
6
|
|
|
7
|
-
const V = require('
|
|
7
|
+
const V = require('./validations');
|
|
8
8
|
|
|
9
9
|
const customTypes = {
|
|
10
10
|
Integer: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const V = require('validator');
|
|
2
|
-
// @ts-ignore
|
|
3
2
|
const _ = require('lodash');
|
|
4
3
|
const {
|
|
5
4
|
crypto: { Signature },
|
|
@@ -13,32 +12,20 @@ const addressValidator = require('wallet-address-validator');
|
|
|
13
12
|
const zilUtils = require('@zilliqa-js/util');
|
|
14
13
|
const web3 = require('web3-utils');
|
|
15
14
|
const stellarSDK = require('stellar-sdk');
|
|
16
|
-
const E = require('
|
|
15
|
+
const E = require('./errors');
|
|
17
16
|
|
|
18
|
-
type Validations = {
|
|
19
|
-
[key: string]: any
|
|
20
|
-
}
|
|
21
17
|
|
|
22
|
-
const validations
|
|
23
|
-
_validate(
|
|
24
|
-
Err: new (msg: string) => Error,
|
|
25
|
-
pred: (x: any) => boolean,
|
|
26
|
-
x: any,
|
|
27
|
-
msg: string,
|
|
28
|
-
) {
|
|
18
|
+
const validations = {
|
|
19
|
+
_validate(Err, pred, x, msg) {
|
|
29
20
|
if (pred(x)) {
|
|
30
21
|
return x;
|
|
31
22
|
}
|
|
32
23
|
throw new Err(msg);
|
|
33
24
|
},
|
|
34
|
-
_validateArg(
|
|
35
|
-
pred: (x: any) => boolean,
|
|
36
|
-
x: any,
|
|
37
|
-
msg: string,
|
|
38
|
-
) {
|
|
25
|
+
_validateArg(pred, x, msg) {
|
|
39
26
|
return this._validate(E.InvalidArguments, pred, x, msg);
|
|
40
27
|
},
|
|
41
|
-
_tryCheck(fn
|
|
28
|
+
_tryCheck(fn, arg) {
|
|
42
29
|
try {
|
|
43
30
|
fn(arg);
|
|
44
31
|
return true;
|
|
@@ -47,35 +34,34 @@ const validations: Validations = {
|
|
|
47
34
|
}
|
|
48
35
|
},
|
|
49
36
|
|
|
50
|
-
exists(x
|
|
37
|
+
exists(x) {
|
|
51
38
|
return x != null;
|
|
52
39
|
},
|
|
53
|
-
nonEmpty(x
|
|
40
|
+
nonEmpty(x) {
|
|
54
41
|
return (x != null ? x.length : undefined) > 0;
|
|
55
42
|
},
|
|
56
|
-
isNonEmptyString(x
|
|
57
|
-
// @ts-ignore
|
|
43
|
+
isNonEmptyString(x) {
|
|
58
44
|
return _.isString(x) && (x != null ? x.length : undefined) > 0;
|
|
59
45
|
},
|
|
60
|
-
ensureShortEnough(limit
|
|
46
|
+
ensureShortEnough(limit, x) {
|
|
61
47
|
const l = x != null ? x.length : undefined;
|
|
62
48
|
if (l <= limit) {
|
|
63
49
|
return true;
|
|
64
50
|
}
|
|
65
51
|
throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
|
|
66
52
|
},
|
|
67
|
-
ensure(crit
|
|
53
|
+
ensure(crit, msg) {
|
|
68
54
|
if (crit) {
|
|
69
55
|
return true;
|
|
70
56
|
}
|
|
71
57
|
throw new E.BadRequest(msg);
|
|
72
58
|
},
|
|
73
|
-
argExists(x
|
|
59
|
+
argExists(x, msg) {
|
|
74
60
|
return this._validateArg(this.exists, x, msg);
|
|
75
61
|
},
|
|
76
62
|
|
|
77
63
|
check: {
|
|
78
|
-
matches(required
|
|
64
|
+
matches(required, given, msg) {
|
|
79
65
|
const newGiven = _.uniq(given);
|
|
80
66
|
const crit = _.intersection(newGiven, required).length === given.length;
|
|
81
67
|
if (crit) {
|
|
@@ -83,8 +69,8 @@ const validations: Validations = {
|
|
|
83
69
|
}
|
|
84
70
|
throw new E.BadRequest(msg);
|
|
85
71
|
},
|
|
86
|
-
wasFound(type
|
|
87
|
-
return (item
|
|
72
|
+
wasFound(type) {
|
|
73
|
+
return (item) => {
|
|
88
74
|
if (item == null) {
|
|
89
75
|
throw new E.NotFound(`Unknown ${type}`);
|
|
90
76
|
} else {
|
|
@@ -92,8 +78,8 @@ const validations: Validations = {
|
|
|
92
78
|
}
|
|
93
79
|
};
|
|
94
80
|
},
|
|
95
|
-
wasCreated(msg
|
|
96
|
-
return (arr
|
|
81
|
+
wasCreated(msg) {
|
|
82
|
+
return (arr) => {
|
|
97
83
|
if (!arr[1]) {
|
|
98
84
|
throw new E.BadRequest(msg);
|
|
99
85
|
} else {
|
|
@@ -101,13 +87,13 @@ const validations: Validations = {
|
|
|
101
87
|
}
|
|
102
88
|
};
|
|
103
89
|
},
|
|
104
|
-
isTrue(crit
|
|
90
|
+
isTrue(crit, msg) {
|
|
105
91
|
if (crit) {
|
|
106
92
|
return true;
|
|
107
93
|
}
|
|
108
94
|
throw new E.BadRequest(msg);
|
|
109
95
|
},
|
|
110
|
-
isFalse(crit
|
|
96
|
+
isFalse(crit, msg) {
|
|
111
97
|
if (!crit) {
|
|
112
98
|
return true;
|
|
113
99
|
}
|
|
@@ -115,45 +101,40 @@ const validations: Validations = {
|
|
|
115
101
|
},
|
|
116
102
|
},
|
|
117
103
|
|
|
118
|
-
isCustomerReference(x
|
|
104
|
+
isCustomerReference(x) {
|
|
119
105
|
return (
|
|
120
106
|
_.isString(x)
|
|
121
|
-
// @ts-ignore
|
|
122
107
|
&& (x != null ? x.length : undefined) > 0
|
|
123
|
-
// @ts-ignore
|
|
124
108
|
&& (x != null ? x.length : undefined) <= 100
|
|
125
109
|
);
|
|
126
110
|
},
|
|
127
|
-
isCustomerLabelName(x
|
|
111
|
+
isCustomerLabelName(x) {
|
|
128
112
|
return (
|
|
129
113
|
_.isString(x)
|
|
130
|
-
// @ts-ignore
|
|
131
114
|
&& (x != null ? x.length : undefined) > 0
|
|
132
|
-
// @ts-ignore
|
|
133
115
|
&& (x != null ? x.length : undefined) <= 50
|
|
134
116
|
);
|
|
135
117
|
},
|
|
136
118
|
binanceCoin: {
|
|
137
|
-
isAddress(str
|
|
119
|
+
isAddress(str) {
|
|
138
120
|
return /^(bnb)([a-z0-9]{39})$/.test(str);
|
|
139
121
|
},
|
|
140
|
-
isTxHash(str
|
|
122
|
+
isTxHash(str) {
|
|
141
123
|
if (!V.isHexadecimal(str)) {
|
|
142
124
|
return false;
|
|
143
125
|
}
|
|
144
126
|
return str.length === 64;
|
|
145
|
-
}
|
|
127
|
+
}
|
|
146
128
|
},
|
|
147
129
|
bitcoin: {
|
|
148
|
-
isAddress(str
|
|
130
|
+
isAddress(str) {
|
|
149
131
|
const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
|
|
150
|
-
|
|
151
132
|
return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
|
|
152
133
|
},
|
|
153
|
-
isBech32Address(str
|
|
134
|
+
isBech32Address(str) {
|
|
154
135
|
return /^bc1[ac-hj-np-z02-9]{6,86}|^BC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
|
|
155
136
|
},
|
|
156
|
-
isHDPublicKey(str
|
|
137
|
+
isHDPublicKey(str) {
|
|
157
138
|
try {
|
|
158
139
|
HDPublicKey(str);
|
|
159
140
|
return true;
|
|
@@ -161,7 +142,7 @@ const validations: Validations = {
|
|
|
161
142
|
return false;
|
|
162
143
|
}
|
|
163
144
|
},
|
|
164
|
-
isPublicKey(str
|
|
145
|
+
isPublicKey(str) {
|
|
165
146
|
try {
|
|
166
147
|
PublicKey(str);
|
|
167
148
|
return true;
|
|
@@ -169,13 +150,13 @@ const validations: Validations = {
|
|
|
169
150
|
return false;
|
|
170
151
|
}
|
|
171
152
|
},
|
|
172
|
-
isTxHash(str
|
|
153
|
+
isTxHash(str) {
|
|
173
154
|
if (!V.isHexadecimal(str)) {
|
|
174
155
|
return false;
|
|
175
156
|
}
|
|
176
157
|
return str.length === 64;
|
|
177
158
|
},
|
|
178
|
-
isTxHex(str
|
|
159
|
+
isTxHex(str) {
|
|
179
160
|
if (!V.isHexadecimal(str)) {
|
|
180
161
|
return false;
|
|
181
162
|
}
|
|
@@ -186,10 +167,10 @@ const validations: Validations = {
|
|
|
186
167
|
return false;
|
|
187
168
|
}
|
|
188
169
|
},
|
|
189
|
-
isHDPath(str
|
|
170
|
+
isHDPath(str) {
|
|
190
171
|
return HDPrivateKey.isValidPath(str);
|
|
191
172
|
},
|
|
192
|
-
isScriptHex(str
|
|
173
|
+
isScriptHex(str) {
|
|
193
174
|
if (!V.isHexadecimal(str)) {
|
|
194
175
|
return false;
|
|
195
176
|
}
|
|
@@ -200,7 +181,7 @@ const validations: Validations = {
|
|
|
200
181
|
return false;
|
|
201
182
|
}
|
|
202
183
|
},
|
|
203
|
-
isTxSignature(str
|
|
184
|
+
isTxSignature(str) {
|
|
204
185
|
if (!V.isHexadecimal(str)) {
|
|
205
186
|
return false;
|
|
206
187
|
}
|
|
@@ -212,15 +193,15 @@ const validations: Validations = {
|
|
|
212
193
|
return false;
|
|
213
194
|
}
|
|
214
195
|
},
|
|
215
|
-
isBlockHeight(obj
|
|
196
|
+
isBlockHeight(obj) {
|
|
216
197
|
return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
|
|
217
198
|
},
|
|
218
199
|
},
|
|
219
200
|
bitcoinCash: {
|
|
220
|
-
isAddress(str
|
|
201
|
+
isAddress(str) {
|
|
221
202
|
return /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bitcoincash:)?[q|p][a-z0-9]{41}$|^(BITCOINCASH:)?[Q|P][A-Z0-9]{41}$/.test(str);
|
|
222
203
|
},
|
|
223
|
-
isTxHash(str
|
|
204
|
+
isTxHash(str) {
|
|
224
205
|
if (!V.isHexadecimal(str)) {
|
|
225
206
|
return false;
|
|
226
207
|
}
|
|
@@ -228,19 +209,19 @@ const validations: Validations = {
|
|
|
228
209
|
},
|
|
229
210
|
},
|
|
230
211
|
ethereum: {
|
|
231
|
-
isAddress(str
|
|
212
|
+
isAddress(str) {
|
|
232
213
|
return web3.isAddress(str);
|
|
233
214
|
},
|
|
234
|
-
isBlockHash(str
|
|
215
|
+
isBlockHash(str) {
|
|
235
216
|
return str.length === 66 && web3.isHexStrict(str);
|
|
236
217
|
},
|
|
237
|
-
isTxHash(str
|
|
218
|
+
isTxHash(str) {
|
|
238
219
|
return str.length === 66 && web3.isHexStrict(str);
|
|
239
220
|
},
|
|
240
|
-
isAddressCode(str
|
|
221
|
+
isAddressCode(str) {
|
|
241
222
|
return web3.isHexStrict(str);
|
|
242
223
|
},
|
|
243
|
-
isValidWeiAmount(str
|
|
224
|
+
isValidWeiAmount(str) {
|
|
244
225
|
try {
|
|
245
226
|
web3.fromWei(str);
|
|
246
227
|
return true;
|
|
@@ -250,21 +231,20 @@ const validations: Validations = {
|
|
|
250
231
|
},
|
|
251
232
|
},
|
|
252
233
|
horizen: {
|
|
253
|
-
isAddress(str
|
|
234
|
+
isAddress(str) {
|
|
254
235
|
return addressValidator.validate(str, 'ZEN');
|
|
255
236
|
},
|
|
256
|
-
isTxHash(str
|
|
237
|
+
isTxHash(str) {
|
|
257
238
|
if (!V.isHexadecimal(str)) {
|
|
258
239
|
return false;
|
|
259
240
|
}
|
|
260
|
-
return str.length === 64;
|
|
261
|
-
},
|
|
241
|
+
return str.length === 64; },
|
|
262
242
|
},
|
|
263
243
|
litecoin: {
|
|
264
|
-
isAddress(str
|
|
244
|
+
isAddress(str) {
|
|
265
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);
|
|
266
246
|
},
|
|
267
|
-
isTxHash(str
|
|
247
|
+
isTxHash(str) {
|
|
268
248
|
if (!V.isHexadecimal(str)) {
|
|
269
249
|
return false;
|
|
270
250
|
}
|
|
@@ -272,10 +252,10 @@ const validations: Validations = {
|
|
|
272
252
|
},
|
|
273
253
|
},
|
|
274
254
|
ripple: {
|
|
275
|
-
isAddress(str
|
|
255
|
+
isAddress(str) {
|
|
276
256
|
return addressValidator.validate(str, 'XRP');
|
|
277
257
|
},
|
|
278
|
-
isTxHash(str
|
|
258
|
+
isTxHash(str) {
|
|
279
259
|
if (!V.isHexadecimal(str)) {
|
|
280
260
|
return false;
|
|
281
261
|
}
|
|
@@ -283,10 +263,10 @@ const validations: Validations = {
|
|
|
283
263
|
},
|
|
284
264
|
},
|
|
285
265
|
stellar: {
|
|
286
|
-
isAddress(str
|
|
266
|
+
isAddress(str) {
|
|
287
267
|
return stellarSDK.StrKey.isValidEd25519PublicKey(str);
|
|
288
268
|
},
|
|
289
|
-
isTxHash(str
|
|
269
|
+
isTxHash(str) {
|
|
290
270
|
if (!V.isHexadecimal(str)) {
|
|
291
271
|
return false;
|
|
292
272
|
}
|
|
@@ -294,10 +274,10 @@ const validations: Validations = {
|
|
|
294
274
|
},
|
|
295
275
|
},
|
|
296
276
|
zcash: {
|
|
297
|
-
isAddress(str
|
|
277
|
+
isAddress(str) {
|
|
298
278
|
return addressValidator.validate(str, 'ZEC');
|
|
299
279
|
},
|
|
300
|
-
isTxHash(str
|
|
280
|
+
isTxHash(str) {
|
|
301
281
|
if (!V.isHexadecimal(str)) {
|
|
302
282
|
return false;
|
|
303
283
|
}
|
|
@@ -305,10 +285,10 @@ const validations: Validations = {
|
|
|
305
285
|
},
|
|
306
286
|
},
|
|
307
287
|
zilliqa: {
|
|
308
|
-
isAddress(str
|
|
288
|
+
isAddress(str) {
|
|
309
289
|
return zilUtils.validation.isBech32(str);
|
|
310
290
|
},
|
|
311
|
-
isTxHash(str
|
|
291
|
+
isTxHash(str) {
|
|
312
292
|
return str.length === 66 && web3.isHexStrict(str);
|
|
313
293
|
},
|
|
314
294
|
},
|
|
@@ -317,7 +297,7 @@ const validations: Validations = {
|
|
|
317
297
|
Object.keys(V).forEach((k) => {
|
|
318
298
|
const v = V[k];
|
|
319
299
|
// don't trigger validation with null values (prevents swagger 500 error)
|
|
320
|
-
validations[k] = (x
|
|
300
|
+
validations[k] = (x) => (x === null ? false : v(x));
|
|
321
301
|
});
|
|
322
302
|
|
|
323
|
-
|
|
303
|
+
module.exports = validations;
|