@ellipticltd/aml-utils 0.15.45 → 0.15.47

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 (67) hide show
  1. package/lib/errors/errors.d.ts +9 -0
  2. package/lib/errors/errors.js +19 -30
  3. package/lib/errors/errors.js.map +1 -0
  4. package/lib/file-parser/errors.d.ts +3 -0
  5. package/lib/file-parser/errors.js +11 -0
  6. package/lib/file-parser/errors.js.map +1 -0
  7. package/lib/file-parser/file-parser.d.ts +6 -0
  8. package/lib/file-parser/file-parser.js +59 -0
  9. package/lib/file-parser/file-parser.js.map +1 -0
  10. package/lib/file-parser/parse-row.d.ts +2 -0
  11. package/lib/file-parser/parse-row.js +40 -0
  12. package/lib/file-parser/parse-row.js.map +1 -0
  13. package/lib/file-parser/sanitizeRows.d.ts +5 -0
  14. package/lib/file-parser/sanitizeRows.js +15 -0
  15. package/lib/file-parser/sanitizeRows.js.map +1 -0
  16. package/lib/formatting/formatting.d.ts +2 -0
  17. package/lib/formatting/formatting.js +11 -12
  18. package/lib/formatting/formatting.js.map +1 -0
  19. package/lib/{index.ts → index.d.ts} +0 -1
  20. package/lib/index.js +21 -0
  21. package/lib/index.js.map +1 -0
  22. package/lib/middleware/middleware.d.ts +4 -0
  23. package/lib/middleware/middleware.js +14 -17
  24. package/lib/middleware/middleware.js.map +1 -0
  25. package/lib/orm-helpers/ormHelpers.d.ts +1 -0
  26. package/lib/orm-helpers/ormHelpers.js +7 -9
  27. package/lib/orm-helpers/ormHelpers.js.map +1 -0
  28. package/lib/structured-file-parser/errors.d.ts +12 -0
  29. package/lib/structured-file-parser/errors.js +33 -0
  30. package/lib/structured-file-parser/errors.js.map +1 -0
  31. package/lib/structured-file-parser/parse-row.d.ts +2 -0
  32. package/lib/structured-file-parser/parse-row.js +40 -0
  33. package/lib/structured-file-parser/parse-row.js.map +1 -0
  34. package/lib/structured-file-parser/sanitize-rows.d.ts +2 -0
  35. package/lib/structured-file-parser/sanitize-rows.js +14 -0
  36. package/lib/structured-file-parser/sanitize-rows.js.map +1 -0
  37. package/lib/structured-file-parser/structured-file-parser.d.ts +10 -0
  38. package/lib/structured-file-parser/structured-file-parser.js +95 -0
  39. package/lib/structured-file-parser/structured-file-parser.js.map +1 -0
  40. package/lib/types/types.d.ts +11 -0
  41. package/lib/types/types.js +190 -200
  42. package/lib/types/types.js.map +1 -0
  43. package/lib/validations/validations.d.ts +215 -0
  44. package/lib/validations/validations.js +575 -572
  45. package/lib/validations/validations.js.map +1 -0
  46. package/package.json +15 -1
  47. package/.eslintrc.js +0 -22
  48. package/dist/libs/aml-utils/libs/aml-utils/README.md +0 -19
  49. package/jest.config.ts +0 -13
  50. package/lib/errors/errors.spec.js +0 -49
  51. package/lib/file-parser/__tests/parse-row.spec.js +0 -34
  52. package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -85
  53. package/lib/file-parser/errors.ts +0 -6
  54. package/lib/file-parser/file-parser.ts +0 -66
  55. package/lib/file-parser/parse-row.ts +0 -46
  56. package/lib/file-parser/sanitizeRows.ts +0 -22
  57. package/lib/formatting/formatting.spec.js +0 -47
  58. package/lib/orm-helpers/ormHelpers.spec.js +0 -47
  59. package/lib/structured-file-parser/errors.ts +0 -25
  60. package/lib/structured-file-parser/parse-row.ts +0 -46
  61. package/lib/structured-file-parser/sanitize-rows.ts +0 -17
  62. package/lib/structured-file-parser/structured-file-parser.ts +0 -128
  63. package/lib/validations/validations.spec.js +0 -1104
  64. package/project.json +0 -55
  65. package/tsconfig.json +0 -13
  66. package/tsconfig.lib.json +0 -14
  67. package/tsconfig.spec.json +0 -10
@@ -1,596 +1,599 @@
1
1
  /* eslint no-underscore-dangle: 0 */
2
2
  const V = require('validator');
3
3
  const _ = require('lodash');
4
- const {
5
- crypto: { Signature },
6
- HDPrivateKey,
7
- HDPublicKey,
8
- PublicKey,
9
- Script,
10
- Transaction,
11
- } = require('bitcore-lib');
4
+ const { crypto: { Signature }, HDPrivateKey, HDPublicKey, PublicKey, Script, Transaction, } = require('bitcore-lib');
12
5
  const addressValidator = require('multicoin-address-validator');
13
6
  const zilUtils = require('@zilliqa-js/util');
14
7
  const web3 = require('web3-utils');
15
8
  const stellarSDK = require('stellar-sdk');
16
9
  const E = require('../errors/errors');
17
-
18
10
  const validations = {
19
- _validate(Err, pred, x, msg) {
20
- if (pred(x)) {
21
- return x;
22
- }
23
- throw new Err(msg);
24
- },
25
- _validateArg(pred, x, msg) {
26
- return this._validate(E.InvalidArguments, pred, x, msg);
27
- },
28
- _tryCheck(fn, arg) {
29
- try {
30
- fn(arg);
31
- return true;
32
- } catch (error) {
33
- return false;
34
- }
35
- },
36
-
37
- exists(x) {
38
- return x != null;
39
- },
40
- nonEmpty(x) {
41
- return (x != null ? x.length : undefined) > 0;
42
- },
43
- isNonEmptyString(x) {
44
- return _.isString(x) && (x != null ? x.length : undefined) > 0;
45
- },
46
- isSafeString(str) {
47
- // eslint-disable-next-line no-useless-escape, prefer-regex-literals
48
- return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,|\$|£|&)+$/, 'u').test(str);
49
- },
50
- isAssetSafeString(str) {
51
- // eslint-disable-next-line no-useless-escape, prefer-regex-literals
52
- return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,|\$|£|&|\/)+$/, 'u').test(str);
53
- },
54
- ensureShortEnough(limit, x) {
55
- const l = x != null ? x.length : undefined;
56
- if (l <= limit) {
57
- return true;
58
- }
59
- throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
60
- },
61
- ensure(crit, msg) {
62
- if (crit) {
63
- return true;
64
- }
65
- throw new E.BadRequest(msg);
66
- },
67
- argExists(x, msg) {
68
- return this._validateArg(this.exists, x, msg);
69
- },
70
-
71
- check: {
72
- matches(required, given, msg) {
73
- const newGiven = _.uniq(given);
74
- const crit = _.intersection(newGiven, required).length === given.length;
75
- if (crit) {
76
- return true;
77
- }
78
- throw new E.BadRequest(msg);
79
- },
80
- wasFound(type) {
81
- return (item) => {
82
- if (item == null) {
83
- throw new E.NotFound(`Unknown ${type}`);
84
- } else {
85
- return item;
11
+ _validate(Err, pred, x, msg) {
12
+ if (pred(x)) {
13
+ return x;
86
14
  }
87
- };
88
- },
89
- wasCreated(msg) {
90
- return (arr) => {
91
- if (!arr[1]) {
92
- throw new E.BadRequest(msg);
93
- } else {
94
- return arr;
95
- }
96
- };
97
- },
98
- isTrue(crit, msg) {
99
- if (crit) {
100
- return true;
101
- }
102
- throw new E.BadRequest(msg);
103
- },
104
- isFalse(crit, msg) {
105
- if (!crit) {
106
- return true;
107
- }
108
- throw new E.BadRequest(msg);
109
- },
110
- },
111
-
112
- isCustomerReference(x) {
113
- return _.isString(x) && (x != null ? x.length : undefined) > 0 && (x != null ? x.length : undefined) <= 100;
114
- },
115
- isCustomerLabelName(x) {
116
- return _.isString(x) && (x != null ? x.length : undefined) > 0 && (x != null ? x.length : undefined) <= 50;
117
- },
118
- binanceChain: {
119
- isAddress(str) {
120
- return /^(bnb)([a-z0-9]{39})$/.test(str);
121
- },
122
- isTxHash(str) {
123
- if (!V.isHexadecimal(str)) {
124
- return false;
125
- }
126
- return str.length === 64;
127
- },
128
- },
129
- bitcoin: {
130
- isAddress(str, asset) {
131
- if (asset === 'lightning') {
132
- return validations.isNonEmptyString(str);
133
- }
134
- const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
135
- return typeof str === 'string' && addressValidator.validate(str.trim(), 'btc', network);
136
- },
137
- isBech32Address(str) {
138
- return /^bc1[ac-hj-np-z02-9]{6,86}|^BC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
139
- },
140
- isHDPublicKey(str) {
141
- try {
142
- HDPublicKey(str);
143
- return true;
144
- } catch (error) {
145
- return false;
146
- }
147
- },
148
- isPublicKey(str) {
149
- try {
150
- PublicKey(str);
151
- return true;
152
- } catch (error) {
153
- return false;
154
- }
155
- },
156
- isTxHash(str) {
157
- if (!V.isHexadecimal(str)) {
158
- return false;
159
- }
160
- return str.length === 64;
161
- },
162
- isTxHex(str) {
163
- if (!V.isHexadecimal(str)) {
164
- return false;
165
- }
166
- try {
167
- Transaction(str);
168
- return true;
169
- } catch (error) {
170
- return false;
171
- }
172
- },
173
- isHDPath(str) {
174
- return HDPrivateKey.isValidPath(str);
175
- },
176
- isScriptHex(str) {
177
- if (!V.isHexadecimal(str)) {
178
- return false;
179
- }
180
- try {
181
- Script(str);
182
- return true;
183
- } catch (error) {
184
- return false;
185
- }
186
- },
187
- isTxSignature(str) {
188
- if (!V.isHexadecimal(str)) {
189
- return false;
190
- }
191
- try {
192
- const b = Buffer.from(str, 'hex');
193
- Signature.fromTxFormat(b);
194
- return true;
195
- } catch (error) {
196
- return false;
197
- }
198
- },
199
- isBlockHeight(obj) {
200
- return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
201
- },
202
- },
203
- bitcoinCash: {
204
- isAddress(str) {
205
- 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);
206
- },
207
- isTxHash(str) {
208
- if (!V.isHexadecimal(str)) {
209
- return false;
210
- }
211
- return str.length === 64;
212
- },
213
- },
214
- ethereum: {
215
- isAddress(str) {
216
- return web3.isAddress(str);
217
- },
218
- isBlockHash(str) {
219
- return str.length === 66 && web3.isHexStrict(str);
220
- },
221
- isTxHash(str) {
222
- return str.length === 66 && web3.isHexStrict(str);
223
- },
224
- isAddressCode(str) {
225
- return web3.isHexStrict(str);
226
- },
227
- isValidWeiAmount(str) {
228
- try {
229
- web3.fromWei(str);
230
- return true;
231
- } catch (e) {
232
- return false;
233
- }
234
- },
235
- },
236
- horizen: {
237
- isAddress(str) {
238
- return addressValidator.validate(str, 'zen');
239
- },
240
- isTxHash(str) {
241
- if (!V.isHexadecimal(str)) {
242
- return false;
243
- }
244
- return str.length === 64;
245
- },
246
- },
247
- litecoin: {
248
- isAddress(str) {
249
- 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}$|^ltcmweb[a-zA-Z0-9]{114}$/.test(
250
- str
251
- );
252
- },
253
- isTxHash(str) {
254
- if (!V.isHexadecimal(str)) {
255
- return false;
256
- }
257
- return str.length === 64;
258
- },
259
- },
260
- ripple: {
261
- isAddress(str) {
262
- return addressValidator.validate(str, 'xrp');
263
- },
264
- isTxHash(str) {
265
- if (!V.isHexadecimal(str)) {
266
- return false;
267
- }
268
- return str.length === 64;
269
- },
270
- },
271
- stellar: {
272
- isAddress(str) {
273
- return stellarSDK.StrKey.isValidEd25519PublicKey(str);
274
- },
275
- isTxHash(str) {
276
- if (!V.isHexadecimal(str)) {
277
- return false;
278
- }
279
- return str.length === 64;
280
- },
281
- },
282
- zcash: {
283
- isAddress(str) {
284
- return addressValidator.validate(str, 'zec');
285
- },
286
- isTxHash(str) {
287
- if (!V.isHexadecimal(str)) {
288
- return false;
289
- }
290
- return str.length === 64;
291
- },
292
- },
293
- zilliqa: {
294
- isAddress(str) {
295
- return zilUtils.validation.isBech32(str);
296
- },
297
- isTxHash(str) {
298
- return str.length === 66 && web3.isHexStrict(str);
299
- },
300
- },
301
- algorand: {
302
- isAddress(str) {
303
- return addressValidator.validate(str, 'algo');
304
- },
305
- isTxHash(str) {
306
- return str.length === 52;
307
- },
308
- },
309
- tezos: {
310
- isAddress(str) {
311
- return str[0] !== 'o' && addressValidator.validate(str, 'xtz');
312
- },
313
- isTxHash(str) {
314
- return str.length === 51;
315
- },
316
- },
317
- polkadot: {
318
- isAddress(str) {
319
- return addressValidator.validate(str, 'dot');
320
- },
321
- isTxHash(str) {
322
- return str.length === 66 && web3.isHexStrict(str);
323
- },
324
- },
325
- cardano: {
326
- isAddress(str) {
327
- return addressValidator.validate(str, 'ada');
328
- },
329
- isTxHash(str) {
330
- if (!V.isHexadecimal(str)) {
331
- return false;
332
- }
333
- return str.length === 64;
334
- },
335
- },
336
- cryptocom: {
337
- isAddress(str) {
338
- return addressValidator.validate(str, 'cro');
339
- },
340
- isTxHash(str) {
341
- if (!V.isHexadecimal(str)) {
342
- return false;
343
- }
344
- return str.length === 64;
345
- },
346
- },
347
- near: {
348
- isAddress(str) {
349
- // https://nomicon.io/DataStructures/Account
350
- return /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(str);
351
- },
352
- isTxHash(str) {
353
- return str.length === 44 || str.length === 43;
354
- },
355
- },
356
- doge: {
357
- isAddress(str) {
358
- return /^[a-zA-Z\d]{34}$/.test(str);
359
- },
360
- isTxHash(str) {
361
- return str.length === 64;
362
- },
363
- },
364
- cosmos: {
365
- isAddress(str) {
366
- return /^cosmos{1}[a-zA-Z\d]{39}$/.test(str);
367
- },
368
- isTxHash(str) {
369
- return str.length === 64 && web3.isHex(str);
370
- },
371
- },
372
- solana: {
373
- isAddress(str) {
374
- return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);
375
- },
376
- isTxHash(str) {
377
- return /^[1-9A-HJ-NP-Za-km-z]{77,88}$/.test(str);
378
- },
379
- },
380
- binanceSmartChain: {
381
- isAddress(str) {
382
- return web3.isAddress(str);
383
- },
384
- isTxHash(str) {
385
- return str.length === 66 && web3.isHexStrict(str);
386
- },
387
- },
388
- polygon: {
389
- isAddress(str) {
390
- return web3.isAddress(str);
391
- },
392
- isTxHash(str) {
393
- return str.length === 66 && web3.isHexStrict(str);
394
- },
395
- },
396
- filecoin: {
397
- isAddress(str) {
398
- return /^(f0|f1|f2|f3)/.test(str);
399
- },
400
- isTxHash(str) {
401
- return str.length === 62 && /^bafy2bza/.test(str);
402
- },
403
- },
404
- optimism: {
405
- isAddress(str) {
406
- return web3.isAddress(str);
407
- },
408
- isTxHash(str) {
409
- return str.length === 66 && web3.isHexStrict(str);
410
- },
411
- },
412
- avalanche: {
413
- isAddress(str) {
414
- return web3.isAddress(str);
415
- },
416
- isTxHash(str) {
417
- return str.length === 66 && web3.isHexStrict(str);
418
- },
419
- },
420
- arbitrum: {
421
- isAddress(str) {
422
- return web3.isAddress(str);
423
- },
424
- isTxHash(str) {
425
- return str.length === 66 && web3.isHexStrict(str);
426
- },
427
- },
428
- tron: {
429
- isAddress(str) {
430
- return addressValidator.validate(str, 'tron');
431
- },
432
- isTxHash(str) {
433
- return str.length === 64 && web3.isHex(str);
434
- },
435
- },
436
- fantom: {
437
- isAddress(str) {
438
- return web3.isAddress(str);
439
- },
440
- isTxHash(str) {
441
- return str.length === 66 && web3.isHexStrict(str);
442
- },
443
- },
444
- celo: {
445
- isAddress(str) {
446
- return web3.isAddress(str);
447
- },
448
- isTxHash(str) {
449
- return str.length === 66 && web3.isHexStrict(str);
450
- },
451
- },
452
- ethereumClassic: {
453
- isAddress(str) {
454
- return web3.isAddress(str);
455
- },
456
- isTxHash(str) {
457
- return str.length === 66 && web3.isHexStrict(str);
458
- },
459
- },
460
- mobilecoin: {
461
- isAddress(str) {
462
- return str.length === 24 && /^[A-Za-z0-9+/]+={0,2}$/.test(str);
463
- },
464
- isTxHash(str) {
465
- return str.length === 64 && web3.isHex(str);
466
- },
467
- },
468
- sui: {
469
- isAddress(str) {
470
- return str.length === 66 && /^[A-Za-z0-9+/]+$/.test(str);
471
- },
472
- isTxHash(str) {
473
- return str.length === 44;
474
- },
475
- },
476
- flare: {
477
- isAddress(str) {
478
- return str.length === 42 && /^[A-Za-z0-9+/]+$/.test(str);
479
- },
480
- isTxHash(str) {
481
- return str.length === 66;
482
- },
483
- },
484
- ton: {
485
- isAddress(str) {
486
- return /^[A-Za-z0-9+/]{64}$/.test(str);
487
- },
488
- isTxHash(str) {
489
- return /^[A-Za-z0-9+/]{64}$/.test(str);
490
- },
491
- },
492
- gnosis: {
493
- isAddress(str) {
494
- return web3.isAddress(str);
495
- },
496
- isTxHash(str) {
497
- return str.length === 66 && web3.isHexStrict(str);
498
- },
499
- },
500
- dydx: {
501
- isAddress(str) {
502
- return /^[a-z]+1[a-zA-Z0-9]{38}$/.test(str) || str === 'dydx_chain';
15
+ throw new Err(msg);
503
16
  },
504
- isTxHash(str) {
505
- return str.length === 64 && web3.isHex(str);
17
+ _validateArg(pred, x, msg) {
18
+ return this._validate(E.InvalidArguments, pred, x, msg);
506
19
  },
507
- },
508
- hederaHashgraph: {
509
- isAddress(str) {
510
- return /^\d+\.\d+\.\d+$/.test(str);
511
- },
512
- isTxHash(str) {
513
- return /^[xa-f0-9+/]{98}$/.test(str);
514
- },
515
- },
516
- aptos: {
517
- isAddress(str) {
518
- return str.length <= 66 && web3.isHex(str);
519
- },
520
- isTxHash(str) {
521
- return web3.isHex(str);
522
- },
523
- },
524
- zksync: {
525
- isAddress(str) {
526
- return web3.isAddress(str);
527
- },
528
- isTxHash(str) {
529
- return str.length === 66 && web3.isHexStrict(str);
530
- },
531
- },
532
- haqq: {
533
- isAddress(str) {
534
- return web3.isAddress(str);
535
- },
536
- isTxHash(str) {
537
- return str.length === 64 && web3.isHex(str);
538
- },
539
- },
540
- base: {
541
- isAddress(str) {
542
- return web3.isAddress(str);
543
- },
544
- isTxHash(str) {
545
- return str.length === 66 && web3.isHexStrict(str);
546
- },
547
- },
548
- corechain: {
549
- isAddress(str) {
550
- return web3.isAddress(str);
551
- },
552
- isTxHash(str) {
553
- return str.length === 66 && web3.isHexStrict(str);
554
- },
555
- },
556
- worldchain: {
557
- isAddress(str) {
558
- return web3.isAddress(str);
20
+ _tryCheck(fn, arg) {
21
+ try {
22
+ fn(arg);
23
+ return true;
24
+ }
25
+ catch (error) {
26
+ return false;
27
+ }
559
28
  },
560
- isTxHash(str) {
561
- return str.length === 66 && web3.isHexStrict(str);
29
+ exists(x) {
30
+ return x != null;
562
31
  },
563
- },
564
- injective: {
565
- isAddress(str) {
566
- return /^[a-z0-9]+$/i.test(str);
32
+ nonEmpty(x) {
33
+ return (x != null ? x.length : undefined) > 0;
567
34
  },
568
- isTxHash(str) {
569
- return str.length === 64 && web3.isHex(str);
35
+ isNonEmptyString(x) {
36
+ return _.isString(x) && (x != null ? x.length : undefined) > 0;
570
37
  },
571
- },
572
- linea: {
573
- isAddress(str) {
574
- return web3.isAddress(str);
38
+ isSafeString(str) {
39
+ // eslint-disable-next-line no-useless-escape, prefer-regex-literals
40
+ return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,|\$|£|&)+$/, 'u').test(str);
575
41
  },
576
- isTxHash(str) {
577
- return str.length === 66 && web3.isHexStrict(str);
42
+ isAssetSafeString(str) {
43
+ // eslint-disable-next-line no-useless-escape, prefer-regex-literals
44
+ return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,|\$|£|&|\/)+$/, 'u').test(str);
578
45
  },
579
- },
580
- xdc: {
581
- isAddress(str) {
582
- return web3.isAddress(str);
46
+ ensureShortEnough(limit, x) {
47
+ const l = x != null ? x.length : undefined;
48
+ if (l <= limit) {
49
+ return true;
50
+ }
51
+ throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
583
52
  },
584
- isTxHash(str) {
585
- return str.length === 66 && web3.isHexStrict(str);
53
+ ensure(crit, msg) {
54
+ if (crit) {
55
+ return true;
56
+ }
57
+ throw new E.BadRequest(msg);
58
+ },
59
+ argExists(x, msg) {
60
+ return this._validateArg(this.exists, x, msg);
61
+ },
62
+ check: {
63
+ matches(required, given, msg) {
64
+ const newGiven = _.uniq(given);
65
+ const crit = _.intersection(newGiven, required).length === given.length;
66
+ if (crit) {
67
+ return true;
68
+ }
69
+ throw new E.BadRequest(msg);
70
+ },
71
+ wasFound(type) {
72
+ return (item) => {
73
+ if (item == null) {
74
+ throw new E.NotFound(`Unknown ${type}`);
75
+ }
76
+ else {
77
+ return item;
78
+ }
79
+ };
80
+ },
81
+ wasCreated(msg) {
82
+ return (arr) => {
83
+ if (!arr[1]) {
84
+ throw new E.BadRequest(msg);
85
+ }
86
+ else {
87
+ return arr;
88
+ }
89
+ };
90
+ },
91
+ isTrue(crit, msg) {
92
+ if (crit) {
93
+ return true;
94
+ }
95
+ throw new E.BadRequest(msg);
96
+ },
97
+ isFalse(crit, msg) {
98
+ if (!crit) {
99
+ return true;
100
+ }
101
+ throw new E.BadRequest(msg);
102
+ },
103
+ },
104
+ isCustomerReference(x) {
105
+ return _.isString(x) && (x != null ? x.length : undefined) > 0 && (x != null ? x.length : undefined) <= 100;
106
+ },
107
+ isCustomerLabelName(x) {
108
+ return _.isString(x) && (x != null ? x.length : undefined) > 0 && (x != null ? x.length : undefined) <= 50;
109
+ },
110
+ binanceChain: {
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, asset) {
123
+ if (asset === 'lightning') {
124
+ return validations.isNonEmptyString(str);
125
+ }
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}$|^ltcmweb[a-zA-Z0-9]{114}$/.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
+ algorand: {
298
+ isAddress(str) {
299
+ return addressValidator.validate(str, 'algo');
300
+ },
301
+ isTxHash(str) {
302
+ return str.length === 52;
303
+ },
304
+ },
305
+ tezos: {
306
+ isAddress(str) {
307
+ return str[0] !== 'o' && addressValidator.validate(str, 'xtz');
308
+ },
309
+ isTxHash(str) {
310
+ return str.length === 51;
311
+ },
312
+ },
313
+ polkadot: {
314
+ isAddress(str) {
315
+ return addressValidator.validate(str, 'dot');
316
+ },
317
+ isTxHash(str) {
318
+ return str.length === 66 && web3.isHexStrict(str);
319
+ },
320
+ },
321
+ cardano: {
322
+ isAddress(str) {
323
+ return addressValidator.validate(str, 'ada');
324
+ },
325
+ isTxHash(str) {
326
+ if (!V.isHexadecimal(str)) {
327
+ return false;
328
+ }
329
+ return str.length === 64;
330
+ },
331
+ },
332
+ cryptocom: {
333
+ isAddress(str) {
334
+ return addressValidator.validate(str, 'cro');
335
+ },
336
+ isTxHash(str) {
337
+ if (!V.isHexadecimal(str)) {
338
+ return false;
339
+ }
340
+ return str.length === 64;
341
+ },
342
+ },
343
+ near: {
344
+ isAddress(str) {
345
+ // https://nomicon.io/DataStructures/Account
346
+ return /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(str);
347
+ },
348
+ isTxHash(str) {
349
+ return str.length === 44 || str.length === 43;
350
+ },
351
+ },
352
+ doge: {
353
+ isAddress(str) {
354
+ return /^[a-zA-Z\d]{34}$/.test(str);
355
+ },
356
+ isTxHash(str) {
357
+ return str.length === 64;
358
+ },
359
+ },
360
+ cosmos: {
361
+ isAddress(str) {
362
+ return /^cosmos{1}[a-zA-Z\d]{39}$/.test(str);
363
+ },
364
+ isTxHash(str) {
365
+ return str.length === 64 && web3.isHex(str);
366
+ },
367
+ },
368
+ solana: {
369
+ isAddress(str) {
370
+ return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);
371
+ },
372
+ isTxHash(str) {
373
+ return /^[1-9A-HJ-NP-Za-km-z]{77,88}$/.test(str);
374
+ },
375
+ },
376
+ binanceSmartChain: {
377
+ isAddress(str) {
378
+ return web3.isAddress(str);
379
+ },
380
+ isTxHash(str) {
381
+ return str.length === 66 && web3.isHexStrict(str);
382
+ },
383
+ },
384
+ polygon: {
385
+ isAddress(str) {
386
+ return web3.isAddress(str);
387
+ },
388
+ isTxHash(str) {
389
+ return str.length === 66 && web3.isHexStrict(str);
390
+ },
391
+ },
392
+ filecoin: {
393
+ isAddress(str) {
394
+ return /^(f0|f1|f2|f3)/.test(str);
395
+ },
396
+ isTxHash(str) {
397
+ return str.length === 62 && /^bafy2bza/.test(str);
398
+ },
399
+ },
400
+ optimism: {
401
+ isAddress(str) {
402
+ return web3.isAddress(str);
403
+ },
404
+ isTxHash(str) {
405
+ return str.length === 66 && web3.isHexStrict(str);
406
+ },
407
+ },
408
+ avalanche: {
409
+ isAddress(str) {
410
+ return web3.isAddress(str);
411
+ },
412
+ isTxHash(str) {
413
+ return str.length === 66 && web3.isHexStrict(str);
414
+ },
415
+ },
416
+ arbitrum: {
417
+ isAddress(str) {
418
+ return web3.isAddress(str);
419
+ },
420
+ isTxHash(str) {
421
+ return str.length === 66 && web3.isHexStrict(str);
422
+ },
423
+ },
424
+ tron: {
425
+ isAddress(str) {
426
+ return addressValidator.validate(str, 'tron');
427
+ },
428
+ isTxHash(str) {
429
+ return str.length === 64 && web3.isHex(str);
430
+ },
431
+ },
432
+ fantom: {
433
+ isAddress(str) {
434
+ return web3.isAddress(str);
435
+ },
436
+ isTxHash(str) {
437
+ return str.length === 66 && web3.isHexStrict(str);
438
+ },
439
+ },
440
+ celo: {
441
+ isAddress(str) {
442
+ return web3.isAddress(str);
443
+ },
444
+ isTxHash(str) {
445
+ return str.length === 66 && web3.isHexStrict(str);
446
+ },
447
+ },
448
+ ethereumClassic: {
449
+ isAddress(str) {
450
+ return web3.isAddress(str);
451
+ },
452
+ isTxHash(str) {
453
+ return str.length === 66 && web3.isHexStrict(str);
454
+ },
455
+ },
456
+ mobilecoin: {
457
+ isAddress(str) {
458
+ return str.length === 24 && /^[A-Za-z0-9+/]+={0,2}$/.test(str);
459
+ },
460
+ isTxHash(str) {
461
+ return str.length === 64 && web3.isHex(str);
462
+ },
463
+ },
464
+ sui: {
465
+ isAddress(str) {
466
+ return str.length === 66 && /^[A-Za-z0-9+/]+$/.test(str);
467
+ },
468
+ isTxHash(str) {
469
+ return str.length === 44;
470
+ },
471
+ },
472
+ flare: {
473
+ isAddress(str) {
474
+ return str.length === 42 && /^[A-Za-z0-9+/]+$/.test(str);
475
+ },
476
+ isTxHash(str) {
477
+ return str.length === 66;
478
+ },
479
+ },
480
+ ton: {
481
+ isAddress(str) {
482
+ return /^[A-Za-z0-9+/]{64}$/.test(str);
483
+ },
484
+ isTxHash(str) {
485
+ return /^[A-Za-z0-9+/]{64}$/.test(str);
486
+ },
487
+ },
488
+ gnosis: {
489
+ isAddress(str) {
490
+ return web3.isAddress(str);
491
+ },
492
+ isTxHash(str) {
493
+ return str.length === 66 && web3.isHexStrict(str);
494
+ },
495
+ },
496
+ dydx: {
497
+ isAddress(str) {
498
+ return /^[a-z]+1[a-zA-Z0-9]{38}$/.test(str) || str === 'dydx_chain';
499
+ },
500
+ isTxHash(str) {
501
+ return str.length === 64 && web3.isHex(str);
502
+ },
503
+ },
504
+ hederaHashgraph: {
505
+ isAddress(str) {
506
+ return /^\d+\.\d+\.\d+$/.test(str);
507
+ },
508
+ isTxHash(str) {
509
+ return /^[xa-f0-9+/]{98}$/.test(str);
510
+ },
511
+ },
512
+ aptos: {
513
+ isAddress(str) {
514
+ return str.length <= 66 && web3.isHex(str);
515
+ },
516
+ isTxHash(str) {
517
+ return web3.isHex(str);
518
+ },
519
+ },
520
+ zksync: {
521
+ isAddress(str) {
522
+ return web3.isAddress(str);
523
+ },
524
+ isTxHash(str) {
525
+ return str.length === 66 && web3.isHexStrict(str);
526
+ },
527
+ },
528
+ haqq: {
529
+ isAddress(str) {
530
+ return web3.isAddress(str);
531
+ },
532
+ isTxHash(str) {
533
+ return str.length === 64 && web3.isHex(str);
534
+ },
535
+ },
536
+ base: {
537
+ isAddress(str) {
538
+ return web3.isAddress(str);
539
+ },
540
+ isTxHash(str) {
541
+ return str.length === 66 && web3.isHexStrict(str);
542
+ },
543
+ },
544
+ corechain: {
545
+ isAddress(str) {
546
+ return web3.isAddress(str);
547
+ },
548
+ isTxHash(str) {
549
+ return str.length === 66 && web3.isHexStrict(str);
550
+ },
551
+ },
552
+ worldchain: {
553
+ isAddress(str) {
554
+ return web3.isAddress(str);
555
+ },
556
+ isTxHash(str) {
557
+ return str.length === 66 && web3.isHexStrict(str);
558
+ },
559
+ },
560
+ injective: {
561
+ isAddress(str) {
562
+ return /^[a-z0-9]+$/i.test(str);
563
+ },
564
+ isTxHash(str) {
565
+ return str.length === 64 && web3.isHex(str);
566
+ },
567
+ },
568
+ linea: {
569
+ isAddress(str) {
570
+ return web3.isAddress(str);
571
+ },
572
+ isTxHash(str) {
573
+ return str.length === 66 && web3.isHexStrict(str);
574
+ },
575
+ },
576
+ xdc: {
577
+ isAddress(str) {
578
+ return web3.isAddress(str);
579
+ },
580
+ isTxHash(str) {
581
+ return str.length === 66 && web3.isHexStrict(str);
582
+ },
583
+ },
584
+ internetcomputer: {
585
+ isAddress(str) {
586
+ return web3.isHex(str);
587
+ },
588
+ isTxHash(str) {
589
+ return web3.isHex(str);
590
+ },
586
591
  },
587
- },
588
592
  };
589
-
590
593
  Object.keys(V).forEach((k) => {
591
- const v = V[k];
592
- // don't trigger validation with null values (prevents swagger 500 error)
593
- validations[k] = (x) => (x === null ? false : v(x));
594
+ const v = V[k];
595
+ // don't trigger validation with null values (prevents swagger 500 error)
596
+ validations[k] = (x) => (x === null ? false : v(x));
594
597
  });
595
-
596
598
  module.exports = validations;
599
+ //# sourceMappingURL=validations.js.map