@ellipticltd/aml-utils 0.15.20 → 0.15.21
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/lib/errors/errors.d.ts +9 -0
- package/lib/errors/errors.js +19 -30
- package/lib/errors/errors.js.map +1 -0
- package/lib/file-parser/errors.d.ts +3 -0
- package/lib/file-parser/errors.js +11 -0
- package/lib/file-parser/errors.js.map +1 -0
- package/lib/file-parser/file-parser.d.ts +6 -0
- package/lib/file-parser/file-parser.js +60 -0
- package/lib/file-parser/file-parser.js.map +1 -0
- package/lib/file-parser/parse-row.d.ts +2 -0
- package/lib/file-parser/parse-row.js +40 -0
- package/lib/file-parser/parse-row.js.map +1 -0
- package/lib/file-parser/sanitizeRows.d.ts +5 -0
- package/lib/file-parser/sanitizeRows.js +15 -0
- package/lib/file-parser/sanitizeRows.js.map +1 -0
- package/lib/formatting/formatting.d.ts +2 -0
- package/lib/formatting/formatting.js +11 -12
- package/lib/formatting/formatting.js.map +1 -0
- package/lib/{index.ts → index.d.ts} +0 -1
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/middleware/middleware.d.ts +4 -0
- package/lib/middleware/middleware.js +14 -17
- package/lib/middleware/middleware.js.map +1 -0
- package/lib/orm-helpers/ormHelpers.d.ts +1 -0
- package/lib/orm-helpers/ormHelpers.js +7 -9
- package/lib/orm-helpers/ormHelpers.js.map +1 -0
- package/lib/structured-file-parser/errors.d.ts +12 -0
- package/lib/structured-file-parser/errors.js +33 -0
- package/lib/structured-file-parser/errors.js.map +1 -0
- package/lib/structured-file-parser/parse-row.d.ts +2 -0
- package/lib/structured-file-parser/parse-row.js +40 -0
- package/lib/structured-file-parser/parse-row.js.map +1 -0
- package/lib/structured-file-parser/sanitize-rows.d.ts +2 -0
- package/lib/structured-file-parser/sanitize-rows.js +14 -0
- package/lib/structured-file-parser/sanitize-rows.js.map +1 -0
- package/lib/structured-file-parser/structured-file-parser.d.ts +10 -0
- package/lib/structured-file-parser/structured-file-parser.js +96 -0
- package/lib/structured-file-parser/structured-file-parser.js.map +1 -0
- package/lib/types/types.d.ts +11 -0
- package/lib/types/types.js +190 -200
- package/lib/types/types.js.map +1 -0
- package/lib/validations/validations.d.ts +159 -0
- package/lib/validations/validations.js +460 -465
- package/lib/validations/validations.js.map +1 -0
- package/package.json +15 -1
- package/.eslintrc.js +0 -22
- package/dist/libs/aml-utils/libs/aml-utils/README.md +0 -19
- package/jest.config.ts +0 -13
- package/lib/errors/errors.spec.js +0 -49
- package/lib/file-parser/__tests/parse-row.spec.js +0 -34
- package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -85
- package/lib/file-parser/errors.ts +0 -6
- package/lib/file-parser/file-parser.ts +0 -67
- package/lib/file-parser/parse-row.ts +0 -46
- package/lib/file-parser/sanitizeRows.ts +0 -22
- package/lib/formatting/formatting.spec.js +0 -47
- package/lib/orm-helpers/ormHelpers.spec.js +0 -47
- package/lib/structured-file-parser/errors.ts +0 -25
- package/lib/structured-file-parser/parse-row.ts +0 -46
- package/lib/structured-file-parser/sanitize-rows.ts +0 -17
- package/lib/structured-file-parser/structured-file-parser.ts +0 -129
- package/lib/validations/validations.spec.js +0 -869
- package/project.json +0 -55
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -13
- package/tsconfig.spec.json +0 -10
|
@@ -1,489 +1,484 @@
|
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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) {
|
|
131
|
-
const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
|
|
132
|
-
return typeof str === 'string' && addressValidator.validate(str.trim(), 'btc', network);
|
|
133
|
-
},
|
|
134
|
-
isBech32Address(str) {
|
|
135
|
-
return /^bc1[ac-hj-np-z02-9]{6,86}|^BC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
|
|
136
|
-
},
|
|
137
|
-
isHDPublicKey(str) {
|
|
138
|
-
try {
|
|
139
|
-
HDPublicKey(str);
|
|
140
|
-
return true;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
isPublicKey(str) {
|
|
146
|
-
try {
|
|
147
|
-
PublicKey(str);
|
|
148
|
-
return true;
|
|
149
|
-
} catch (error) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
isTxHash(str) {
|
|
154
|
-
if (!V.isHexadecimal(str)) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
return str.length === 64;
|
|
158
|
-
},
|
|
159
|
-
isTxHex(str) {
|
|
160
|
-
if (!V.isHexadecimal(str)) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
Transaction(str);
|
|
165
|
-
return true;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
isHDPath(str) {
|
|
171
|
-
return HDPrivateKey.isValidPath(str);
|
|
172
|
-
},
|
|
173
|
-
isScriptHex(str) {
|
|
174
|
-
if (!V.isHexadecimal(str)) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
Script(str);
|
|
179
|
-
return true;
|
|
180
|
-
} catch (error) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
isTxSignature(str) {
|
|
185
|
-
if (!V.isHexadecimal(str)) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
const b = Buffer.from(str, 'hex');
|
|
190
|
-
Signature.fromTxFormat(b);
|
|
191
|
-
return true;
|
|
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
|
-
} catch (e) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
horizen: {
|
|
234
|
-
isAddress(str) {
|
|
235
|
-
return addressValidator.validate(str, 'zen');
|
|
236
|
-
},
|
|
237
|
-
isTxHash(str) {
|
|
238
|
-
if (!V.isHexadecimal(str)) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
return str.length === 64;
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
|
-
litecoin: {
|
|
245
|
-
isAddress(str) {
|
|
246
|
-
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(
|
|
247
|
-
str
|
|
248
|
-
);
|
|
249
|
-
},
|
|
250
|
-
isTxHash(str) {
|
|
251
|
-
if (!V.isHexadecimal(str)) {
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
return str.length === 64;
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
ripple: {
|
|
258
|
-
isAddress(str) {
|
|
259
|
-
return addressValidator.validate(str, 'xrp');
|
|
260
|
-
},
|
|
261
|
-
isTxHash(str) {
|
|
262
|
-
if (!V.isHexadecimal(str)) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
return str.length === 64;
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
stellar: {
|
|
269
|
-
isAddress(str) {
|
|
270
|
-
return stellarSDK.StrKey.isValidEd25519PublicKey(str);
|
|
271
|
-
},
|
|
272
|
-
isTxHash(str) {
|
|
273
|
-
if (!V.isHexadecimal(str)) {
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
return str.length === 64;
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
zcash: {
|
|
280
|
-
isAddress(str) {
|
|
281
|
-
return addressValidator.validate(str, 'zec');
|
|
282
|
-
},
|
|
283
|
-
isTxHash(str) {
|
|
284
|
-
if (!V.isHexadecimal(str)) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
return str.length === 64;
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
zilliqa: {
|
|
291
|
-
isAddress(str) {
|
|
292
|
-
return zilUtils.validation.isBech32(str);
|
|
293
|
-
},
|
|
294
|
-
isTxHash(str) {
|
|
295
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
algorand: {
|
|
299
|
-
isAddress(str) {
|
|
300
|
-
return addressValidator.validate(str, 'algo');
|
|
301
|
-
},
|
|
302
|
-
isTxHash(str) {
|
|
303
|
-
return str.length === 52;
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
tezos: {
|
|
307
|
-
isAddress(str) {
|
|
308
|
-
return str[0] !== 'o' && addressValidator.validate(str, 'xtz');
|
|
309
|
-
},
|
|
310
|
-
isTxHash(str) {
|
|
311
|
-
return str.length === 51;
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
polkadot: {
|
|
315
|
-
isAddress(str) {
|
|
316
|
-
return addressValidator.validate(str, 'dot');
|
|
317
|
-
},
|
|
318
|
-
isTxHash(str) {
|
|
319
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
cardano: {
|
|
323
|
-
isAddress(str) {
|
|
324
|
-
return addressValidator.validate(str, 'ada');
|
|
325
|
-
},
|
|
326
|
-
isTxHash(str) {
|
|
327
|
-
if (!V.isHexadecimal(str)) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
return str.length === 64;
|
|
331
|
-
},
|
|
332
|
-
},
|
|
333
|
-
cryptocom: {
|
|
334
|
-
isAddress(str) {
|
|
335
|
-
return addressValidator.validate(str, 'cro');
|
|
336
|
-
},
|
|
337
|
-
isTxHash(str) {
|
|
338
|
-
if (!V.isHexadecimal(str)) {
|
|
339
|
-
return false;
|
|
340
|
-
}
|
|
341
|
-
return str.length === 64;
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
near: {
|
|
345
|
-
isAddress(str) {
|
|
346
|
-
// https://nomicon.io/DataStructures/Account
|
|
347
|
-
return /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(str);
|
|
348
|
-
},
|
|
349
|
-
isTxHash(str) {
|
|
350
|
-
return str.length === 44 || str.length === 43;
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
doge: {
|
|
354
|
-
isAddress(str) {
|
|
355
|
-
return /^[a-zA-Z\d]{34}$/.test(str);
|
|
356
|
-
},
|
|
357
|
-
isTxHash(str) {
|
|
358
|
-
return str.length === 64;
|
|
359
|
-
},
|
|
360
|
-
},
|
|
361
|
-
cosmos: {
|
|
362
|
-
isAddress(str) {
|
|
363
|
-
return /^cosmos{1}[a-zA-Z\d]{39}$/.test(str);
|
|
364
|
-
},
|
|
365
|
-
isTxHash(str) {
|
|
366
|
-
return str.length === 64 && web3.isHex(str);
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
solana: {
|
|
370
|
-
isAddress(str) {
|
|
371
|
-
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);
|
|
372
|
-
},
|
|
373
|
-
isTxHash(str) {
|
|
374
|
-
return /^[1-9A-HJ-NP-Za-km-z]{77,88}$/.test(str);
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
binanceSmartChain: {
|
|
378
|
-
isAddress(str) {
|
|
379
|
-
return web3.isAddress(str);
|
|
380
|
-
},
|
|
381
|
-
isTxHash(str) {
|
|
382
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
383
|
-
},
|
|
384
|
-
},
|
|
385
|
-
polygon: {
|
|
386
|
-
isAddress(str) {
|
|
387
|
-
return web3.isAddress(str);
|
|
388
|
-
},
|
|
389
|
-
isTxHash(str) {
|
|
390
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
391
|
-
},
|
|
392
|
-
},
|
|
393
|
-
filecoin: {
|
|
394
|
-
isAddress(str) {
|
|
395
|
-
return /^(f0|f1|f2|f3)/.test(str);
|
|
396
|
-
},
|
|
397
|
-
isTxHash(str) {
|
|
398
|
-
return str.length === 62 && /^bafy2bza/.test(str);
|
|
399
|
-
},
|
|
400
|
-
},
|
|
401
|
-
optimism: {
|
|
402
|
-
isAddress(str) {
|
|
403
|
-
return web3.isAddress(str);
|
|
404
|
-
},
|
|
405
|
-
isTxHash(str) {
|
|
406
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
avalanche: {
|
|
410
|
-
isAddress(str) {
|
|
411
|
-
return web3.isAddress(str);
|
|
412
|
-
},
|
|
413
|
-
isTxHash(str) {
|
|
414
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
415
|
-
},
|
|
416
|
-
},
|
|
417
|
-
arbitrum: {
|
|
418
|
-
isAddress(str) {
|
|
419
|
-
return web3.isAddress(str);
|
|
420
|
-
},
|
|
421
|
-
isTxHash(str) {
|
|
422
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
tron: {
|
|
426
|
-
isAddress(str) {
|
|
427
|
-
return addressValidator.validate(str, 'tron');
|
|
428
|
-
},
|
|
429
|
-
isTxHash(str) {
|
|
430
|
-
return str.length === 64 && web3.isHex(str);
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
fantom: {
|
|
434
|
-
isAddress(str) {
|
|
435
|
-
return web3.isAddress(str);
|
|
436
|
-
},
|
|
437
|
-
isTxHash(str) {
|
|
438
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
celo: {
|
|
442
|
-
isAddress(str) {
|
|
443
|
-
return web3.isAddress(str);
|
|
15
|
+
throw new Err(msg);
|
|
444
16
|
},
|
|
445
|
-
|
|
446
|
-
|
|
17
|
+
_validateArg(pred, x, msg) {
|
|
18
|
+
return this._validate(E.InvalidArguments, pred, x, msg);
|
|
447
19
|
},
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
20
|
+
_tryCheck(fn, arg) {
|
|
21
|
+
try {
|
|
22
|
+
fn(arg);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
452
28
|
},
|
|
453
|
-
|
|
454
|
-
|
|
29
|
+
exists(x) {
|
|
30
|
+
return x != null;
|
|
455
31
|
},
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
isAddress(str) {
|
|
459
|
-
return str.length === 24 && /^[A-Za-z0-9+/]+={0,2}$/.test(str);
|
|
32
|
+
nonEmpty(x) {
|
|
33
|
+
return (x != null ? x.length : undefined) > 0;
|
|
460
34
|
},
|
|
461
|
-
|
|
462
|
-
|
|
35
|
+
isNonEmptyString(x) {
|
|
36
|
+
return _.isString(x) && (x != null ? x.length : undefined) > 0;
|
|
463
37
|
},
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
return str.length === 66 && /^[A-Za-z0-9+/]+$/.test(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);
|
|
468
41
|
},
|
|
469
|
-
|
|
470
|
-
|
|
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);
|
|
471
45
|
},
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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}`);
|
|
476
52
|
},
|
|
477
|
-
|
|
478
|
-
|
|
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) {
|
|
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}$|^ltcmweb[a-zA-Z0-9]{114}$/.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
|
+
algorand: {
|
|
295
|
+
isAddress(str) {
|
|
296
|
+
return addressValidator.validate(str, 'algo');
|
|
297
|
+
},
|
|
298
|
+
isTxHash(str) {
|
|
299
|
+
return str.length === 52;
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
tezos: {
|
|
303
|
+
isAddress(str) {
|
|
304
|
+
return str[0] !== 'o' && addressValidator.validate(str, 'xtz');
|
|
305
|
+
},
|
|
306
|
+
isTxHash(str) {
|
|
307
|
+
return str.length === 51;
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
polkadot: {
|
|
311
|
+
isAddress(str) {
|
|
312
|
+
return addressValidator.validate(str, 'dot');
|
|
313
|
+
},
|
|
314
|
+
isTxHash(str) {
|
|
315
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
cardano: {
|
|
319
|
+
isAddress(str) {
|
|
320
|
+
return addressValidator.validate(str, 'ada');
|
|
321
|
+
},
|
|
322
|
+
isTxHash(str) {
|
|
323
|
+
if (!V.isHexadecimal(str)) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return str.length === 64;
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
cryptocom: {
|
|
330
|
+
isAddress(str) {
|
|
331
|
+
return addressValidator.validate(str, 'cro');
|
|
332
|
+
},
|
|
333
|
+
isTxHash(str) {
|
|
334
|
+
if (!V.isHexadecimal(str)) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
return str.length === 64;
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
near: {
|
|
341
|
+
isAddress(str) {
|
|
342
|
+
// https://nomicon.io/DataStructures/Account
|
|
343
|
+
return /^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(str);
|
|
344
|
+
},
|
|
345
|
+
isTxHash(str) {
|
|
346
|
+
return str.length === 44 || str.length === 43;
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
doge: {
|
|
350
|
+
isAddress(str) {
|
|
351
|
+
return /^[a-zA-Z\d]{34}$/.test(str);
|
|
352
|
+
},
|
|
353
|
+
isTxHash(str) {
|
|
354
|
+
return str.length === 64;
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
cosmos: {
|
|
358
|
+
isAddress(str) {
|
|
359
|
+
return /^cosmos{1}[a-zA-Z\d]{39}$/.test(str);
|
|
360
|
+
},
|
|
361
|
+
isTxHash(str) {
|
|
362
|
+
return str.length === 64 && web3.isHex(str);
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
solana: {
|
|
366
|
+
isAddress(str) {
|
|
367
|
+
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(str);
|
|
368
|
+
},
|
|
369
|
+
isTxHash(str) {
|
|
370
|
+
return /^[1-9A-HJ-NP-Za-km-z]{77,88}$/.test(str);
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
binanceSmartChain: {
|
|
374
|
+
isAddress(str) {
|
|
375
|
+
return web3.isAddress(str);
|
|
376
|
+
},
|
|
377
|
+
isTxHash(str) {
|
|
378
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
polygon: {
|
|
382
|
+
isAddress(str) {
|
|
383
|
+
return web3.isAddress(str);
|
|
384
|
+
},
|
|
385
|
+
isTxHash(str) {
|
|
386
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
filecoin: {
|
|
390
|
+
isAddress(str) {
|
|
391
|
+
return /^(f0|f1|f2|f3)/.test(str);
|
|
392
|
+
},
|
|
393
|
+
isTxHash(str) {
|
|
394
|
+
return str.length === 62 && /^bafy2bza/.test(str);
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
optimism: {
|
|
398
|
+
isAddress(str) {
|
|
399
|
+
return web3.isAddress(str);
|
|
400
|
+
},
|
|
401
|
+
isTxHash(str) {
|
|
402
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
avalanche: {
|
|
406
|
+
isAddress(str) {
|
|
407
|
+
return web3.isAddress(str);
|
|
408
|
+
},
|
|
409
|
+
isTxHash(str) {
|
|
410
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
arbitrum: {
|
|
414
|
+
isAddress(str) {
|
|
415
|
+
return web3.isAddress(str);
|
|
416
|
+
},
|
|
417
|
+
isTxHash(str) {
|
|
418
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
tron: {
|
|
422
|
+
isAddress(str) {
|
|
423
|
+
return addressValidator.validate(str, 'tron');
|
|
424
|
+
},
|
|
425
|
+
isTxHash(str) {
|
|
426
|
+
return str.length === 64 && web3.isHex(str);
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
fantom: {
|
|
430
|
+
isAddress(str) {
|
|
431
|
+
return web3.isAddress(str);
|
|
432
|
+
},
|
|
433
|
+
isTxHash(str) {
|
|
434
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
celo: {
|
|
438
|
+
isAddress(str) {
|
|
439
|
+
return web3.isAddress(str);
|
|
440
|
+
},
|
|
441
|
+
isTxHash(str) {
|
|
442
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
ethereumClassic: {
|
|
446
|
+
isAddress(str) {
|
|
447
|
+
return web3.isAddress(str);
|
|
448
|
+
},
|
|
449
|
+
isTxHash(str) {
|
|
450
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
451
|
+
},
|
|
452
|
+
},
|
|
453
|
+
mobilecoin: {
|
|
454
|
+
isAddress(str) {
|
|
455
|
+
return str.length === 24 && /^[A-Za-z0-9+/]+={0,2}$/.test(str);
|
|
456
|
+
},
|
|
457
|
+
isTxHash(str) {
|
|
458
|
+
return str.length === 64 && web3.isHex(str);
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
sui: {
|
|
462
|
+
isAddress(str) {
|
|
463
|
+
return str.length === 66 && /^[A-Za-z0-9+/]+$/.test(str);
|
|
464
|
+
},
|
|
465
|
+
isTxHash(str) {
|
|
466
|
+
return str.length === 44;
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
flare: {
|
|
470
|
+
isAddress(str) {
|
|
471
|
+
return str.length === 42 && /^[A-Za-z0-9+/]+$/.test(str);
|
|
472
|
+
},
|
|
473
|
+
isTxHash(str) {
|
|
474
|
+
return str.length === 66;
|
|
475
|
+
},
|
|
479
476
|
},
|
|
480
|
-
},
|
|
481
477
|
};
|
|
482
|
-
|
|
483
478
|
Object.keys(V).forEach((k) => {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
479
|
+
const v = V[k];
|
|
480
|
+
// don't trigger validation with null values (prevents swagger 500 error)
|
|
481
|
+
validations[k] = (x) => (x === null ? false : v(x));
|
|
487
482
|
});
|
|
488
|
-
|
|
489
483
|
module.exports = validations;
|
|
484
|
+
//# sourceMappingURL=validations.js.map
|