@ellipticltd/aml-utils 0.0.3 → 0.0.10

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,303 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const V = require('validator');
4
- // @ts-ignore
5
- const _ = require('lodash');
6
- const { crypto: { Signature }, HDPrivateKey, HDPublicKey, PublicKey, Script, Transaction, } = require('bitcore-lib');
7
- const addressValidator = require('wallet-address-validator');
8
- const zilUtils = require('@zilliqa-js/util');
9
- const web3 = require('web3-utils');
10
- const stellarSDK = require('stellar-sdk');
11
- const E = require('../errors/errors');
12
- const validations = {
13
- _validate(Err, pred, x, msg) {
14
- if (pred(x)) {
15
- return x;
16
- }
17
- throw new Err(msg);
18
- },
19
- _validateArg(pred, x, msg) {
20
- return this._validate(E.InvalidArguments, pred, x, msg);
21
- },
22
- _tryCheck(fn, arg) {
23
- try {
24
- fn(arg);
25
- return true;
26
- }
27
- catch (error) {
28
- return false;
29
- }
30
- },
31
- exists(x) {
32
- return x != null;
33
- },
34
- nonEmpty(x) {
35
- return (x != null ? x.length : undefined) > 0;
36
- },
37
- isNonEmptyString(x) {
38
- // @ts-ignore
39
- return _.isString(x) && (x != null ? x.length : undefined) > 0;
40
- },
41
- ensureShortEnough(limit, x) {
42
- const l = x != null ? x.length : undefined;
43
- if (l <= limit) {
44
- return true;
45
- }
46
- throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
47
- },
48
- ensure(crit, msg) {
49
- if (crit) {
50
- return true;
51
- }
52
- throw new E.BadRequest(msg);
53
- },
54
- argExists(x, msg) {
55
- return this._validateArg(this.exists, x, msg);
56
- },
57
- check: {
58
- matches(required, given, msg) {
59
- const newGiven = _.uniq(given);
60
- const crit = _.intersection(newGiven, required).length === given.length;
61
- if (crit) {
62
- return true;
63
- }
64
- throw new E.BadRequest(msg);
65
- },
66
- wasFound(type) {
67
- return (item) => {
68
- if (item == null) {
69
- throw new E.NotFound(`Unknown ${type}`);
70
- }
71
- else {
72
- return item;
73
- }
74
- };
75
- },
76
- wasCreated(msg) {
77
- return (arr) => {
78
- if (!arr[1]) {
79
- throw new E.BadRequest(msg);
80
- }
81
- else {
82
- return arr;
83
- }
84
- };
85
- },
86
- isTrue(crit, msg) {
87
- if (crit) {
88
- return true;
89
- }
90
- throw new E.BadRequest(msg);
91
- },
92
- isFalse(crit, msg) {
93
- if (!crit) {
94
- return true;
95
- }
96
- throw new E.BadRequest(msg);
97
- },
98
- },
99
- isCustomerReference(x) {
100
- return (_.isString(x)
101
- // @ts-ignore
102
- && (x != null ? x.length : undefined) > 0
103
- // @ts-ignore
104
- && (x != null ? x.length : undefined) <= 100);
105
- },
106
- isCustomerLabelName(x) {
107
- return (_.isString(x)
108
- // @ts-ignore
109
- && (x != null ? x.length : undefined) > 0
110
- // @ts-ignore
111
- && (x != null ? x.length : undefined) <= 50);
112
- },
113
- binanceCoin: {
114
- isAddress(str) {
115
- return /^(bnb)([a-z0-9]{39})$/.test(str);
116
- },
117
- isTxHash(str) {
118
- if (!V.isHexadecimal(str)) {
119
- return false;
120
- }
121
- return str.length === 64;
122
- },
123
- },
124
- bitcoin: {
125
- isAddress(str) {
126
- const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
127
- return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
128
- },
129
- isBech32Address(str) {
130
- return /^bc1[ac-hj-np-z02-9]{6,86}|^BC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
131
- },
132
- isHDPublicKey(str) {
133
- try {
134
- HDPublicKey(str);
135
- return true;
136
- }
137
- catch (error) {
138
- return false;
139
- }
140
- },
141
- isPublicKey(str) {
142
- try {
143
- PublicKey(str);
144
- return true;
145
- }
146
- catch (error) {
147
- return false;
148
- }
149
- },
150
- isTxHash(str) {
151
- if (!V.isHexadecimal(str)) {
152
- return false;
153
- }
154
- return str.length === 64;
155
- },
156
- isTxHex(str) {
157
- if (!V.isHexadecimal(str)) {
158
- return false;
159
- }
160
- try {
161
- Transaction(str);
162
- return true;
163
- }
164
- catch (error) {
165
- return false;
166
- }
167
- },
168
- isHDPath(str) {
169
- return HDPrivateKey.isValidPath(str);
170
- },
171
- isScriptHex(str) {
172
- if (!V.isHexadecimal(str)) {
173
- return false;
174
- }
175
- try {
176
- Script(str);
177
- return true;
178
- }
179
- catch (error) {
180
- return false;
181
- }
182
- },
183
- isTxSignature(str) {
184
- if (!V.isHexadecimal(str)) {
185
- return false;
186
- }
187
- try {
188
- const b = Buffer.from(str, 'hex');
189
- Signature.fromTxFormat(b);
190
- return true;
191
- }
192
- catch (error) {
193
- return false;
194
- }
195
- },
196
- isBlockHeight(obj) {
197
- return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
198
- },
199
- },
200
- bitcoinCash: {
201
- isAddress(str) {
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);
203
- },
204
- isTxHash(str) {
205
- if (!V.isHexadecimal(str)) {
206
- return false;
207
- }
208
- return str.length === 64;
209
- },
210
- },
211
- ethereum: {
212
- isAddress(str) {
213
- return web3.isAddress(str);
214
- },
215
- isBlockHash(str) {
216
- return str.length === 66 && web3.isHexStrict(str);
217
- },
218
- isTxHash(str) {
219
- return str.length === 66 && web3.isHexStrict(str);
220
- },
221
- isAddressCode(str) {
222
- return web3.isHexStrict(str);
223
- },
224
- isValidWeiAmount(str) {
225
- try {
226
- web3.fromWei(str);
227
- return true;
228
- }
229
- catch (e) {
230
- return false;
231
- }
232
- },
233
- },
234
- horizen: {
235
- isAddress(str) {
236
- return addressValidator.validate(str, 'ZEN');
237
- },
238
- isTxHash(str) {
239
- if (!V.isHexadecimal(str)) {
240
- return false;
241
- }
242
- return str.length === 64;
243
- },
244
- },
245
- litecoin: {
246
- isAddress(str) {
247
- 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);
248
- },
249
- isTxHash(str) {
250
- if (!V.isHexadecimal(str)) {
251
- return false;
252
- }
253
- return str.length === 64;
254
- },
255
- },
256
- ripple: {
257
- isAddress(str) {
258
- return addressValidator.validate(str, 'XRP');
259
- },
260
- isTxHash(str) {
261
- if (!V.isHexadecimal(str)) {
262
- return false;
263
- }
264
- return str.length === 64;
265
- },
266
- },
267
- stellar: {
268
- isAddress(str) {
269
- return stellarSDK.StrKey.isValidEd25519PublicKey(str);
270
- },
271
- isTxHash(str) {
272
- if (!V.isHexadecimal(str)) {
273
- return false;
274
- }
275
- return str.length === 64;
276
- },
277
- },
278
- zcash: {
279
- isAddress(str) {
280
- return addressValidator.validate(str, 'ZEC');
281
- },
282
- isTxHash(str) {
283
- if (!V.isHexadecimal(str)) {
284
- return false;
285
- }
286
- return str.length === 64;
287
- },
288
- },
289
- zilliqa: {
290
- isAddress(str) {
291
- return zilUtils.validation.isBech32(str);
292
- },
293
- isTxHash(str) {
294
- return str.length === 66 && web3.isHexStrict(str);
295
- },
296
- },
297
- };
298
- Object.keys(V).forEach((k) => {
299
- const v = V[k];
300
- // don't trigger validation with null values (prevents swagger 500 error)
301
- validations[k] = (x) => (x === null ? false : v(x));
302
- });
303
- exports.default = validations;
@@ -1,118 +0,0 @@
1
- export function _validate(Err: any, pred: any, x: any, msg: any): any;
2
- export function _validate(Err: any, pred: any, x: any, msg: any): any;
3
- export function _validateArg(pred: any, x: any, msg: any): any;
4
- export function _validateArg(pred: any, x: any, msg: any): any;
5
- export function _tryCheck(fn: any, arg: any): boolean;
6
- export function _tryCheck(fn: any, arg: any): boolean;
7
- export function exists(x: any): boolean;
8
- export function exists(x: any): boolean;
9
- export function nonEmpty(x: any): boolean;
10
- export function nonEmpty(x: any): boolean;
11
- export function isNonEmptyString(x: any): boolean;
12
- export function isNonEmptyString(x: any): boolean;
13
- export function isSafeString(str: any): boolean;
14
- export function isSafeString(str: any): boolean;
15
- export function ensureShortEnough(limit: any, x: any): boolean;
16
- export function ensureShortEnough(limit: any, x: any): boolean;
17
- export function ensure(crit: any, msg: any): boolean;
18
- export function ensure(crit: any, msg: any): boolean;
19
- export function argExists(x: any, msg: any): any;
20
- export function argExists(x: any, msg: any): any;
21
- export namespace check {
22
- function matches(required: any, given: any, msg: any): boolean;
23
- function matches(required: any, given: any, msg: any): boolean;
24
- function wasFound(type: any): (item: any) => any;
25
- function wasFound(type: any): (item: any) => any;
26
- function wasCreated(msg: any): (arr: any) => any;
27
- function wasCreated(msg: any): (arr: any) => any;
28
- function isTrue(crit: any, msg: any): boolean;
29
- function isTrue(crit: any, msg: any): boolean;
30
- function isFalse(crit: any, msg: any): boolean;
31
- function isFalse(crit: any, msg: any): boolean;
32
- }
33
- export function isCustomerReference(x: any): boolean;
34
- export function isCustomerReference(x: any): boolean;
35
- export function isCustomerLabelName(x: any): boolean;
36
- export function isCustomerLabelName(x: any): boolean;
37
- export namespace binanceCoin {
38
- function isAddress(str: any): boolean;
39
- function isAddress(str: any): boolean;
40
- function isTxHash(str: any): boolean;
41
- function isTxHash(str: any): boolean;
42
- }
43
- export namespace bitcoin {
44
- function isAddress(str: any): any;
45
- function isAddress(str: any): any;
46
- function isBech32Address(str: any): boolean;
47
- function isBech32Address(str: any): boolean;
48
- function isHDPublicKey(str: any): boolean;
49
- function isHDPublicKey(str: any): boolean;
50
- function isPublicKey(str: any): boolean;
51
- function isPublicKey(str: any): boolean;
52
- function isTxHash(str: any): boolean;
53
- function isTxHash(str: any): boolean;
54
- function isTxHex(str: any): boolean;
55
- function isTxHex(str: any): boolean;
56
- function isHDPath(str: any): any;
57
- function isHDPath(str: any): any;
58
- function isScriptHex(str: any): boolean;
59
- function isScriptHex(str: any): boolean;
60
- function isTxSignature(str: any): boolean;
61
- function isTxSignature(str: any): boolean;
62
- function isBlockHeight(obj: any): boolean;
63
- function isBlockHeight(obj: any): boolean;
64
- }
65
- export namespace bitcoinCash {
66
- function isAddress(str: any): boolean;
67
- function isAddress(str: any): boolean;
68
- function isTxHash(str: any): boolean;
69
- function isTxHash(str: any): boolean;
70
- }
71
- export namespace ethereum {
72
- function isAddress(str: any): any;
73
- function isAddress(str: any): any;
74
- function isBlockHash(str: any): any;
75
- function isBlockHash(str: any): any;
76
- function isTxHash(str: any): any;
77
- function isTxHash(str: any): any;
78
- function isAddressCode(str: any): any;
79
- function isAddressCode(str: any): any;
80
- function isValidWeiAmount(str: any): boolean;
81
- function isValidWeiAmount(str: any): boolean;
82
- }
83
- export namespace horizen {
84
- function isAddress(str: any): any;
85
- function isAddress(str: any): any;
86
- function isTxHash(str: any): boolean;
87
- function isTxHash(str: any): boolean;
88
- }
89
- export namespace litecoin {
90
- function isAddress(str: any): boolean;
91
- function isAddress(str: any): boolean;
92
- function isTxHash(str: any): boolean;
93
- function isTxHash(str: any): boolean;
94
- }
95
- export namespace ripple {
96
- function isAddress(str: any): any;
97
- function isAddress(str: any): any;
98
- function isTxHash(str: any): boolean;
99
- function isTxHash(str: any): boolean;
100
- }
101
- export namespace stellar {
102
- function isAddress(str: any): boolean;
103
- function isAddress(str: any): boolean;
104
- function isTxHash(str: any): boolean;
105
- function isTxHash(str: any): boolean;
106
- }
107
- export namespace zcash {
108
- function isAddress(str: any): any;
109
- function isAddress(str: any): any;
110
- function isTxHash(str: any): boolean;
111
- function isTxHash(str: any): boolean;
112
- }
113
- export namespace zilliqa {
114
- function isAddress(str: any): boolean;
115
- function isAddress(str: any): boolean;
116
- function isTxHash(str: any): any;
117
- function isTxHash(str: any): any;
118
- }
@@ -1,300 +0,0 @@
1
- "use strict";
2
- const V = require('validator');
3
- const _ = require('lodash');
4
- const { crypto: { Signature }, HDPrivateKey, HDPublicKey, PublicKey, Script, Transaction, } = require('bitcore-lib');
5
- const addressValidator = require('wallet-address-validator');
6
- const zilUtils = require('@zilliqa-js/util');
7
- const web3 = require('web3-utils');
8
- const stellarSDK = require('stellar-sdk');
9
- const E = require('../errors/errors');
10
- const validations = {
11
- _validate(Err, pred, x, msg) {
12
- if (pred(x)) {
13
- return x;
14
- }
15
- throw new Err(msg);
16
- },
17
- _validateArg(pred, x, msg) {
18
- return this._validate(E.InvalidArguments, pred, x, msg);
19
- },
20
- _tryCheck(fn, arg) {
21
- try {
22
- fn(arg);
23
- return true;
24
- }
25
- catch (error) {
26
- return false;
27
- }
28
- },
29
- exists(x) {
30
- return x != null;
31
- },
32
- nonEmpty(x) {
33
- return (x != null ? x.length : undefined) > 0;
34
- },
35
- isNonEmptyString(x) {
36
- return _.isString(x) && (x != null ? x.length : undefined) > 0;
37
- },
38
- isSafeString(str) {
39
- // eslint-disable-next-line no-useless-escape
40
- return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,)+$/, 'u').test(str);
41
- },
42
- ensureShortEnough(limit, x) {
43
- const l = x != null ? x.length : undefined;
44
- if (l <= limit) {
45
- return true;
46
- }
47
- throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
48
- },
49
- ensure(crit, msg) {
50
- if (crit) {
51
- return true;
52
- }
53
- throw new E.BadRequest(msg);
54
- },
55
- argExists(x, msg) {
56
- return this._validateArg(this.exists, x, msg);
57
- },
58
- check: {
59
- matches(required, given, msg) {
60
- const newGiven = _.uniq(given);
61
- const crit = _.intersection(newGiven, required).length === given.length;
62
- if (crit) {
63
- return true;
64
- }
65
- throw new E.BadRequest(msg);
66
- },
67
- wasFound(type) {
68
- return (item) => {
69
- if (item == null) {
70
- throw new E.NotFound(`Unknown ${type}`);
71
- }
72
- else {
73
- return item;
74
- }
75
- };
76
- },
77
- wasCreated(msg) {
78
- return (arr) => {
79
- if (!arr[1]) {
80
- throw new E.BadRequest(msg);
81
- }
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;
96
- }
97
- throw new E.BadRequest(msg);
98
- },
99
- },
100
- isCustomerReference(x) {
101
- return (_.isString(x)
102
- && (x != null ? x.length : undefined) > 0
103
- && (x != null ? x.length : undefined) <= 100);
104
- },
105
- isCustomerLabelName(x) {
106
- return (_.isString(x)
107
- && (x != null ? x.length : undefined) > 0
108
- && (x != null ? x.length : undefined) <= 50);
109
- },
110
- binanceCoin: {
111
- isAddress(str) {
112
- return /^(bnb)([a-z0-9]{39})$/.test(str);
113
- },
114
- isTxHash(str) {
115
- if (!V.isHexadecimal(str)) {
116
- return false;
117
- }
118
- return str.length === 64;
119
- },
120
- },
121
- bitcoin: {
122
- isAddress(str) {
123
- const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
124
- return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
125
- },
126
- isBech32Address(str) {
127
- return /^bc1[ac-hj-np-z02-9]{6,86}|^BC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
128
- },
129
- isHDPublicKey(str) {
130
- try {
131
- HDPublicKey(str);
132
- return true;
133
- }
134
- catch (error) {
135
- return false;
136
- }
137
- },
138
- isPublicKey(str) {
139
- try {
140
- PublicKey(str);
141
- return true;
142
- }
143
- catch (error) {
144
- return false;
145
- }
146
- },
147
- isTxHash(str) {
148
- if (!V.isHexadecimal(str)) {
149
- return false;
150
- }
151
- return str.length === 64;
152
- },
153
- isTxHex(str) {
154
- if (!V.isHexadecimal(str)) {
155
- return false;
156
- }
157
- try {
158
- Transaction(str);
159
- return true;
160
- }
161
- catch (error) {
162
- return false;
163
- }
164
- },
165
- isHDPath(str) {
166
- return HDPrivateKey.isValidPath(str);
167
- },
168
- isScriptHex(str) {
169
- if (!V.isHexadecimal(str)) {
170
- return false;
171
- }
172
- try {
173
- Script(str);
174
- return true;
175
- }
176
- catch (error) {
177
- return false;
178
- }
179
- },
180
- isTxSignature(str) {
181
- if (!V.isHexadecimal(str)) {
182
- return false;
183
- }
184
- try {
185
- const b = Buffer.from(str, 'hex');
186
- Signature.fromTxFormat(b);
187
- return true;
188
- }
189
- catch (error) {
190
- return false;
191
- }
192
- },
193
- isBlockHeight(obj) {
194
- return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
195
- },
196
- },
197
- bitcoinCash: {
198
- isAddress(str) {
199
- 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);
200
- },
201
- isTxHash(str) {
202
- if (!V.isHexadecimal(str)) {
203
- return false;
204
- }
205
- return str.length === 64;
206
- },
207
- },
208
- ethereum: {
209
- isAddress(str) {
210
- return web3.isAddress(str);
211
- },
212
- isBlockHash(str) {
213
- return str.length === 66 && web3.isHexStrict(str);
214
- },
215
- isTxHash(str) {
216
- return str.length === 66 && web3.isHexStrict(str);
217
- },
218
- isAddressCode(str) {
219
- return web3.isHexStrict(str);
220
- },
221
- isValidWeiAmount(str) {
222
- try {
223
- web3.fromWei(str);
224
- return true;
225
- }
226
- catch (e) {
227
- return false;
228
- }
229
- },
230
- },
231
- horizen: {
232
- isAddress(str) {
233
- return addressValidator.validate(str, 'ZEN');
234
- },
235
- isTxHash(str) {
236
- if (!V.isHexadecimal(str)) {
237
- return false;
238
- }
239
- return str.length === 64;
240
- },
241
- },
242
- litecoin: {
243
- isAddress(str) {
244
- 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);
245
- },
246
- isTxHash(str) {
247
- if (!V.isHexadecimal(str)) {
248
- return false;
249
- }
250
- return str.length === 64;
251
- },
252
- },
253
- ripple: {
254
- isAddress(str) {
255
- return addressValidator.validate(str, 'XRP');
256
- },
257
- isTxHash(str) {
258
- if (!V.isHexadecimal(str)) {
259
- return false;
260
- }
261
- return str.length === 64;
262
- },
263
- },
264
- stellar: {
265
- isAddress(str) {
266
- return stellarSDK.StrKey.isValidEd25519PublicKey(str);
267
- },
268
- isTxHash(str) {
269
- if (!V.isHexadecimal(str)) {
270
- return false;
271
- }
272
- return str.length === 64;
273
- },
274
- },
275
- zcash: {
276
- isAddress(str) {
277
- return addressValidator.validate(str, 'ZEC');
278
- },
279
- isTxHash(str) {
280
- if (!V.isHexadecimal(str)) {
281
- return false;
282
- }
283
- return str.length === 64;
284
- },
285
- },
286
- zilliqa: {
287
- isAddress(str) {
288
- return zilUtils.validation.isBech32(str);
289
- },
290
- isTxHash(str) {
291
- return str.length === 66 && web3.isHexStrict(str);
292
- },
293
- },
294
- };
295
- Object.keys(V).forEach((k) => {
296
- const v = V[k];
297
- // don't trigger validation with null values (prevents swagger 500 error)
298
- validations[k] = (x) => (x === null ? false : v(x));
299
- });
300
- module.exports = validations;