@ellipticltd/aml-utils 0.0.3 → 0.0.9

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 (55) hide show
  1. package/.eslintrc +3 -0
  2. package/.nvmrc +1 -0
  3. package/README.md +8 -0
  4. package/index.js +8 -12
  5. package/lib/errors.js +53 -51
  6. package/lib/formatting.js +15 -25
  7. package/lib/middleware.js +20 -28
  8. package/lib/ormHelpers.js +17 -26
  9. package/lib/types.js +202 -170
  10. package/lib/validations.js +189 -174
  11. package/package.json +22 -7
  12. package/.idea/aml-utils.iml +0 -12
  13. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  14. package/.idea/misc.xml +0 -6
  15. package/.idea/modules.xml +0 -8
  16. package/.idea/vcs.xml +0 -6
  17. package/.idea/workspace.xml +0 -283
  18. package/dist/errors/errors.d.ts +0 -9
  19. package/dist/errors/errors.js +0 -42
  20. package/dist/errors/errors.spec.d.ts +0 -1
  21. package/dist/errors/errors.spec.js +0 -23
  22. package/dist/file-parser/__tests/file-parser.spec.d.ts +0 -1
  23. package/dist/file-parser/__tests/file-parser.spec.js +0 -118
  24. package/dist/file-parser/__tests/parse-row.spec.d.ts +0 -1
  25. package/dist/file-parser/__tests/parse-row.spec.js +0 -29
  26. package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +0 -1
  27. package/dist/file-parser/__tests/sanitize-rows.spec.js +0 -78
  28. package/dist/file-parser/errors.d.ts +0 -3
  29. package/dist/file-parser/errors.js +0 -11
  30. package/dist/file-parser/file-parser.d.ts +0 -8
  31. package/dist/file-parser/file-parser.js +0 -68
  32. package/dist/file-parser/parse-row.d.ts +0 -2
  33. package/dist/file-parser/parse-row.js +0 -39
  34. package/dist/file-parser/sanitzeRows.d.ts +0 -3
  35. package/dist/file-parser/sanitzeRows.js +0 -18
  36. package/dist/formatting/formatting.d.ts +0 -2
  37. package/dist/formatting/formatting.js +0 -17
  38. package/dist/formatting/formatting.spec.d.ts +0 -1
  39. package/dist/formatting/formatting.spec.js +0 -37
  40. package/dist/index.d.ts +0 -8
  41. package/dist/index.js +0 -20
  42. package/dist/middleware/middleware.d.ts +0 -4
  43. package/dist/middleware/middleware.js +0 -22
  44. package/dist/orm-helpers/ormHelpers.d.ts +0 -1
  45. package/dist/orm-helpers/ormHelpers.js +0 -17
  46. package/dist/orm-helpers/ormHelpers.spec.d.ts +0 -1
  47. package/dist/orm-helpers/ormHelpers.spec.js +0 -38
  48. package/dist/types/types.d.ts +0 -17
  49. package/dist/types/types.js +0 -203
  50. package/dist/validations/old.validations.d.ts +0 -5
  51. package/dist/validations/old.validations.js +0 -303
  52. package/dist/validations/validations.d.ts +0 -118
  53. package/dist/validations/validations.js +0 -300
  54. package/dist/validations/validations.spec.d.ts +0 -1
  55. package/dist/validations/validations.spec.js +0 -287
@@ -1,199 +1,214 @@
1
- // Generated by CoffeeScript 1.10.0
2
- (function() {
3
- var Address, E, HDPrivateKey, HDPublicKey, PublicKey, Script, Signature, Transaction, V, _, k, ref, ref1, v, validations;
1
+ const E = require('./errors');
2
+ const V = require('validator');
3
+ const _ = require('lodash');
4
+ const {
5
+ crypto: { Signature },
6
+ HDPrivateKey,
7
+ HDPublicKey,
8
+ PublicKey,
9
+ Script,
10
+ Transaction,
11
+ } = require('bitcore-lib');
12
+ const addressValidator = require('wallet-address-validator');
13
+ const web3 = require('web3-utils');
4
14
 
5
- E = require('./errors');
6
-
7
- V = require('validator');
8
-
9
- _ = require('lodash');
15
+ const validations = {
16
+ _validate(Err, pred, x, msg) {
17
+ if (pred(x)) {
18
+ return x;
19
+ }
20
+ throw new Err(msg);
21
+ },
22
+ _validateArg(pred, x, msg) {
23
+ return this._validate(E.InvalidArguments, pred, x, msg);
24
+ },
25
+ _tryCheck(fn, arg) {
26
+ try {
27
+ fn(arg);
28
+ return true;
29
+ } catch (error) {
30
+ return false;
31
+ }
32
+ },
10
33
 
11
- ref = require('bitcore-lib'), (ref1 = ref.crypto, Signature = ref1.Signature), Address = ref.Address, HDPrivateKey = ref.HDPrivateKey, HDPublicKey = ref.HDPublicKey, PublicKey = ref.PublicKey, Script = ref.Script, Transaction = ref.Transaction;
34
+ exists(x) {
35
+ return x != null;
36
+ },
37
+ nonEmpty(x) {
38
+ return (x != null ? x.length : undefined) > 0;
39
+ },
40
+ isNonEmptyString(x) {
41
+ return _.isString(x) && (x != null ? x.length : undefined) > 0;
42
+ },
43
+ ensureShortEnough(limit, x) {
44
+ const l = x != null ? x.length : undefined;
45
+ if (l <= limit) {
46
+ return true;
47
+ }
48
+ throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
49
+ },
50
+ ensure(crit, msg) {
51
+ if (crit) {
52
+ return true;
53
+ }
54
+ throw new E.BadRequest(msg);
55
+ },
56
+ argExists(x, msg) {
57
+ return this._validateArg(this.exists, x, msg);
58
+ },
12
59
 
13
- validations = {
14
- _validate: function(err, pred, x, msg) {
15
- if (pred(x)) {
16
- return x;
17
- } else {
18
- throw new err(msg);
60
+ check: {
61
+ matches(required, given, msg) {
62
+ given = _.uniq(given);
63
+ const crit = _.intersection(given, required).length === given.length;
64
+ if (crit) {
65
+ return true;
66
+ }
67
+ throw new E.BadRequest(msg);
68
+ },
69
+ wasFound(type) {
70
+ return (item) => {
71
+ if (item == null) {
72
+ throw new E.NotFound(`Unknown ${type}`);
73
+ } else {
74
+ return item;
75
+ }
76
+ };
77
+ },
78
+ wasCreated(msg) {
79
+ return (arr) => {
80
+ if (!arr[1]) {
81
+ throw new E.BadRequest(msg);
82
+ } else {
83
+ return arr;
84
+ }
85
+ };
86
+ },
87
+ isTrue(crit, msg) {
88
+ if (crit) {
89
+ return true;
90
+ }
91
+ throw new E.BadRequest(msg);
92
+ },
93
+ isFalse(crit, msg) {
94
+ if (!crit) {
95
+ return true;
19
96
  }
97
+ throw new E.BadRequest(msg);
98
+ },
99
+ },
100
+
101
+ isCustomerReference(x) {
102
+ return (
103
+ _.isString(x) &&
104
+ (x != null ? x.length : undefined) > 0 &&
105
+ (x != null ? x.length : undefined) <= 100
106
+ );
107
+ },
108
+ isCustomerLabelName(x) {
109
+ return (
110
+ _.isString(x) &&
111
+ (x != null ? x.length : undefined) > 0 &&
112
+ (x != null ? x.length : undefined) <= 50
113
+ );
114
+ },
115
+ ethereum: {
116
+ isAddress(str) {
117
+ return web3.isAddress(str);
118
+ },
119
+ isBlockHash(str) {
120
+ return str.length === 66 && web3.isHexStrict(str);
20
121
  },
21
- _validateArg: function(pred, x, msg) {
22
- return this._validate(E.InvalidArguments, pred, x, msg);
122
+ isTxHash(str) {
123
+ return str.length === 66 && web3.isHexStrict(str);
23
124
  },
24
- _tryCheck: function(fn, arg) {
25
- var error;
125
+ isAddressCode(str) {
126
+ return web3.isHexStrict(str);
127
+ },
128
+ isValidWeiAmount(str) {
26
129
  try {
27
- fn(arg);
130
+ web3.fromWei(str);
28
131
  return true;
29
- } catch (error) {
132
+ } catch (e) {
30
133
  return false;
31
134
  }
32
135
  },
33
- exists: function(x) {
34
- return x != null;
35
- },
36
- nonEmpty: function(x) {
37
- return (x != null ? x.length : void 0) > 0;
136
+ },
137
+ bitcoin: {
138
+ isAddress(str) {
139
+ const network =
140
+ process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'livenet';
141
+ return addressValidator(str, network);
38
142
  },
39
- isNonEmptyString: function(x) {
40
- return _.isString(x) && (x != null ? x.length : void 0) > 0;
143
+ isHDPublicKey(str) {
144
+ try {
145
+ HDPublicKey(str);
146
+ return true;
147
+ } catch (error) {
148
+ return false;
149
+ }
41
150
  },
42
- ensureShortEnough: function(limit, x) {
43
- var l;
44
- l = x != null ? x.length : void 0;
45
- if (l <= limit) {
151
+ isPublicKey(str) {
152
+ try {
153
+ PublicKey(str);
46
154
  return true;
47
- } else {
48
- throw new E.BadRequest("Max query size exceeded: " + l + " / " + limit);
155
+ } catch (error) {
156
+ return false;
49
157
  }
50
158
  },
51
- ensure: function(crit, msg) {
52
- if (crit) {
159
+ isTxHash(str) {
160
+ if (!V.isHexadecimal(`${str}`)) {
161
+ return false;
162
+ }
163
+ return str.length === 64;
164
+ },
165
+ isTxHex(str) {
166
+ if (!V.isHexadecimal(`${str}`)) {
167
+ return false;
168
+ }
169
+ try {
170
+ Transaction(str);
53
171
  return true;
54
- } else {
55
- throw new E.BadRequest(msg);
172
+ } catch (error) {
173
+ return false;
56
174
  }
57
175
  },
58
- argExists: function(x, msg) {
59
- return this._validateArg(this.exists, x, msg);
176
+ isHDPath(str) {
177
+ return HDPrivateKey.isValidPath(str);
60
178
  },
61
- check: {
62
- matches: function(required, given, msg) {
63
- var crit;
64
- given = _.uniq(given);
65
- crit = _.intersection(given, required).length === given.length;
66
- if (crit) {
67
- return true;
68
- } else {
69
- throw new E.BadRequest(msg);
70
- }
71
- },
72
- wasFound: function(type) {
73
- return function(item) {
74
- if (item == null) {
75
- throw new E.NotFound("Unknown " + type);
76
- } else {
77
- return item;
78
- }
79
- };
80
- },
81
- wasCreated: function(msg) {
82
- return function(arr) {
83
- if (!arr[1]) {
84
- throw new E.BadRequest(msg);
85
- } else {
86
- return arr;
87
- }
88
- };
89
- },
90
- isTrue: function(crit, msg) {
91
- if (crit) {
92
- return true;
93
- } else {
94
- throw new E.BadRequest(msg);
95
- }
96
- },
97
- isFalse: function(crit, msg) {
98
- if (!crit) {
99
- return true;
100
- } else {
101
- throw new E.BadRequest(msg);
102
- }
179
+ isScriptHex(str) {
180
+ if (!V.isHexadecimal(`${str}`)) {
181
+ return false;
182
+ }
183
+ try {
184
+ Script(str);
185
+ return true;
186
+ } catch (error) {
187
+ return false;
103
188
  }
104
189
  },
105
- isCustomerReference: function(x) {
106
- return _.isString(x) && (x != null ? x.length : void 0) > 0 && (x != null ? x.length : void 0) <= 100;
107
- },
108
- isCustomerLabelName: function(x) {
109
- return _.isString(x) && (x != null ? x.length : void 0) > 0 && (x != null ? x.length : void 0) <= 50;
110
- },
111
- bitcoin: {
112
- isAddress: function(str) {
113
- var error, network;
114
- network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'livenet';
115
- try {
116
- Address(str, network);
117
- return true;
118
- } catch (error) {
119
- return false;
120
- }
121
- },
122
- isHDPublicKey: function(str) {
123
- var error;
124
- try {
125
- HDPublicKey(str);
126
- return true;
127
- } catch (error) {
128
- return false;
129
- }
130
- },
131
- isPublicKey: function(str) {
132
- var error;
133
- try {
134
- PublicKey(str);
135
- return true;
136
- } catch (error) {
137
- return false;
138
- }
139
- },
140
- isTxHash: function(str) {
141
- if (!V.isHexadecimal(str + '')) {
142
- return false;
143
- }
144
- return str.length === 64;
145
- },
146
- isTxHex: function(str) {
147
- var error;
148
- if (!V.isHexadecimal(str + '')) {
149
- return false;
150
- }
151
- try {
152
- Transaction(str);
153
- return true;
154
- } catch (error) {
155
- return false;
156
- }
157
- },
158
- isHDPath: function(str) {
159
- return HDPrivateKey.isValidPath(str);
160
- },
161
- isScriptHex: function(str) {
162
- var error;
163
- if (!V.isHexadecimal(str + '')) {
164
- return false;
165
- }
166
- try {
167
- Script(str);
168
- return true;
169
- } catch (error) {
170
- return false;
171
- }
172
- },
173
- isTxSignature: function(str) {
174
- var b, error;
175
- if (!V.isHexadecimal(str + '')) {
176
- return false;
177
- }
178
- try {
179
- b = new Buffer(str, 'hex');
180
- Signature.fromTxFormat(b);
181
- return true;
182
- } catch (error) {
183
- return false;
184
- }
185
- },
186
- isBlockHeight: function(obj) {
187
- return _.isInteger(+obj) && parseInt(obj) >= 0;
190
+ isTxSignature(str) {
191
+ if (!V.isHexadecimal(`${str}`)) {
192
+ return false;
188
193
  }
189
- }
190
- };
191
-
192
- for (k in V) {
193
- v = V[k];
194
- validations[k] = v;
195
- }
194
+ try {
195
+ const b = Buffer.from(str, 'hex');
196
+ Signature.fromTxFormat(b);
197
+ return true;
198
+ } catch (error) {
199
+ return false;
200
+ }
201
+ },
202
+ isBlockHeight(obj) {
203
+ return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
204
+ },
205
+ },
206
+ };
196
207
 
197
- module.exports = validations;
208
+ Object.keys(V).forEach((k) => {
209
+ const v = V[k];
210
+ // don't trigger validation with null values (prevents swagger 500 error)
211
+ validations[k] = x => (x === null ? false : v(x));
212
+ });
198
213
 
199
- }).call(this);
214
+ module.exports = validations;
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@ellipticltd/aml-utils",
3
- "version": "0.0.3",
3
+ "version": "0.0.9",
4
4
  "description": "Utilities, helpers, validations, type-checking, etc",
5
+ "engines": {
6
+ "node": "10.1.0",
7
+ "npm": "6.1.0"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@bitbucket.org/elliptic/aml-utils.git"
12
+ },
13
+ "homepage": "https://bitbucket.org/elliptic/aml-utils#readme",
5
14
  "main": "index.js",
6
15
  "scripts": {
7
16
  "test": "./node_modules/.bin/mocha --reporter spec --compilers coffee:coffee-script/register --require 'test/index.coffee'",
@@ -11,15 +20,21 @@
11
20
  "author": "Adam Joyce <adam@ellipitc.co>",
12
21
  "license": "MIT",
13
22
  "dependencies": {
14
- "bitcore-lib": "0.13.19",
23
+ "bitcore-lib": "5.0.0-beta.1",
15
24
  "create-error": "0.3.1",
16
- "lodash": "4.14.2",
25
+ "lodash": "4.17.4",
17
26
  "type-check": "0.3.2",
18
- "validator": "5.5.0"
27
+ "validator": "10.10.0",
28
+ "wallet-address-validator": "0.2.4",
29
+ "web3-utils": "1.0.0-beta.28"
19
30
  },
20
31
  "devDependencies": {
21
- "chai": "^3.5.0",
22
- "coffee-script": "1.10.0",
23
- "mocha": "^3.0.2"
32
+ "@ellipticltd/eslint-config": "0.0.3",
33
+ "chai": "4.1.1",
34
+ "coffee-script": "1.12.7",
35
+ "eslint": "5.9.0",
36
+ "eslint-config-airbnb-base": "13.1.0",
37
+ "eslint-plugin-import": "2.14.0",
38
+ "mocha": "3.5.0"
24
39
  }
25
40
  }
@@ -1,12 +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
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
- <excludeFolder url="file://$MODULE_DIR$/temp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
@@ -1,6 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
- </profile>
6
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptSettings">
4
- <option name="languageLevel" value="ES6" />
5
- </component>
6
- </project>
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
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>