@ellipticltd/aml-utils 0.15.18 → 0.15.20
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/.eslintrc.js +22 -0
- package/dist/libs/aml-utils/libs/aml-utils/README.md +19 -0
- package/jest.config.ts +13 -0
- package/lib/errors/errors.js +30 -19
- package/lib/errors/errors.spec.js +49 -0
- package/lib/file-parser/__tests/parse-row.spec.js +34 -0
- package/lib/file-parser/__tests/sanitize-rows.spec.js +85 -0
- package/lib/file-parser/errors.ts +6 -0
- package/lib/file-parser/file-parser.ts +67 -0
- package/lib/file-parser/parse-row.ts +46 -0
- package/lib/file-parser/sanitizeRows.ts +22 -0
- package/lib/formatting/formatting.js +12 -11
- package/lib/formatting/formatting.spec.js +47 -0
- package/lib/{index.d.ts → index.ts} +1 -0
- package/lib/middleware/middleware.js +17 -14
- package/lib/orm-helpers/ormHelpers.js +9 -7
- package/lib/orm-helpers/ormHelpers.spec.js +47 -0
- package/lib/structured-file-parser/errors.ts +25 -0
- package/lib/structured-file-parser/parse-row.ts +46 -0
- package/lib/structured-file-parser/sanitize-rows.ts +17 -0
- package/lib/structured-file-parser/structured-file-parser.ts +129 -0
- package/lib/types/types.js +200 -190
- package/lib/validations/validations.js +465 -444
- package/lib/validations/validations.spec.js +869 -0
- package/package.json +1 -16
- package/project.json +55 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lib.json +13 -0
- package/tsconfig.spec.json +10 -0
- package/lib/errors/errors.d.ts +0 -9
- package/lib/errors/errors.js.map +0 -1
- package/lib/file-parser/errors.d.ts +0 -3
- package/lib/file-parser/errors.js +0 -11
- package/lib/file-parser/errors.js.map +0 -1
- package/lib/file-parser/file-parser.d.ts +0 -6
- package/lib/file-parser/file-parser.js +0 -60
- package/lib/file-parser/file-parser.js.map +0 -1
- package/lib/file-parser/parse-row.d.ts +0 -2
- package/lib/file-parser/parse-row.js +0 -40
- package/lib/file-parser/parse-row.js.map +0 -1
- package/lib/file-parser/sanitizeRows.d.ts +0 -5
- package/lib/file-parser/sanitizeRows.js +0 -15
- package/lib/file-parser/sanitizeRows.js.map +0 -1
- package/lib/formatting/formatting.d.ts +0 -2
- package/lib/formatting/formatting.js.map +0 -1
- package/lib/index.js +0 -21
- package/lib/index.js.map +0 -1
- package/lib/middleware/middleware.d.ts +0 -4
- package/lib/middleware/middleware.js.map +0 -1
- package/lib/orm-helpers/ormHelpers.d.ts +0 -1
- package/lib/orm-helpers/ormHelpers.js.map +0 -1
- package/lib/structured-file-parser/errors.d.ts +0 -12
- package/lib/structured-file-parser/errors.js +0 -33
- package/lib/structured-file-parser/errors.js.map +0 -1
- package/lib/structured-file-parser/parse-row.d.ts +0 -2
- package/lib/structured-file-parser/parse-row.js +0 -40
- package/lib/structured-file-parser/parse-row.js.map +0 -1
- package/lib/structured-file-parser/sanitize-rows.d.ts +0 -2
- package/lib/structured-file-parser/sanitize-rows.js +0 -14
- package/lib/structured-file-parser/sanitize-rows.js.map +0 -1
- package/lib/structured-file-parser/structured-file-parser.d.ts +0 -10
- package/lib/structured-file-parser/structured-file-parser.js +0 -96
- package/lib/structured-file-parser/structured-file-parser.js.map +0 -1
- package/lib/types/types.d.ts +0 -17
- package/lib/types/types.js.map +0 -1
- package/lib/validations/validations.d.ts +0 -240
- package/lib/validations/validations.js.map +0 -1
|
@@ -1,468 +1,489 @@
|
|
|
1
1
|
/* eslint no-underscore-dangle: 0 */
|
|
2
2
|
const V = require('validator');
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
crypto: { Signature },
|
|
6
|
+
HDPrivateKey,
|
|
7
|
+
HDPublicKey,
|
|
8
|
+
PublicKey,
|
|
9
|
+
Script,
|
|
10
|
+
Transaction,
|
|
11
|
+
} = require('bitcore-lib');
|
|
5
12
|
const addressValidator = require('multicoin-address-validator');
|
|
6
13
|
const zilUtils = require('@zilliqa-js/util');
|
|
7
14
|
const web3 = require('web3-utils');
|
|
8
15
|
const stellarSDK = require('stellar-sdk');
|
|
9
16
|
const E = require('../errors/errors');
|
|
17
|
+
|
|
10
18
|
const validations = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
14
86
|
}
|
|
15
|
-
|
|
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);
|
|
16
431
|
},
|
|
17
|
-
|
|
18
|
-
|
|
432
|
+
},
|
|
433
|
+
fantom: {
|
|
434
|
+
isAddress(str) {
|
|
435
|
+
return web3.isAddress(str);
|
|
19
436
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
fn(arg);
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
437
|
+
isTxHash(str) {
|
|
438
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
28
439
|
},
|
|
29
|
-
|
|
30
|
-
|
|
440
|
+
},
|
|
441
|
+
celo: {
|
|
442
|
+
isAddress(str) {
|
|
443
|
+
return web3.isAddress(str);
|
|
31
444
|
},
|
|
32
|
-
|
|
33
|
-
|
|
445
|
+
isTxHash(str) {
|
|
446
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
34
447
|
},
|
|
35
|
-
|
|
36
|
-
|
|
448
|
+
},
|
|
449
|
+
ethereumClassic: {
|
|
450
|
+
isAddress(str) {
|
|
451
|
+
return web3.isAddress(str);
|
|
37
452
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return RegExp(/^(\p{L}|[0-9]|-|=|!|\.|:|\s|@|\+|_|,|\$|£|&)+$/, 'u').test(str);
|
|
453
|
+
isTxHash(str) {
|
|
454
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
41
455
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
456
|
+
},
|
|
457
|
+
mobilecoin: {
|
|
458
|
+
isAddress(str) {
|
|
459
|
+
return str.length === 24 && /^[A-Za-z0-9+/]+={0,2}$/.test(str);
|
|
45
460
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (l <= limit) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
|
|
461
|
+
isTxHash(str) {
|
|
462
|
+
return str.length === 64 && web3.isHex(str);
|
|
52
463
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
},
|
|
464
|
+
},
|
|
465
|
+
sui: {
|
|
466
|
+
isAddress(str) {
|
|
467
|
+
return str.length === 66 && /^[A-Za-z0-9+/]+$/.test(str);
|
|
468
|
+
},
|
|
469
|
+
isTxHash(str) {
|
|
470
|
+
return str.length === 44;
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
flare: {
|
|
474
|
+
isAddress(str) {
|
|
475
|
+
return str.length === 42 && /^[A-Za-z0-9+/]+$/.test(str);
|
|
476
|
+
},
|
|
477
|
+
isTxHash(str) {
|
|
478
|
+
return str.length === 66;
|
|
460
479
|
},
|
|
480
|
+
},
|
|
461
481
|
};
|
|
482
|
+
|
|
462
483
|
Object.keys(V).forEach((k) => {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
484
|
+
const v = V[k];
|
|
485
|
+
// don't trigger validation with null values (prevents swagger 500 error)
|
|
486
|
+
validations[k] = (x) => (x === null ? false : v(x));
|
|
466
487
|
});
|
|
488
|
+
|
|
467
489
|
module.exports = validations;
|
|
468
|
-
//# sourceMappingURL=validations.js.map
|