@ellipticltd/aml-utils 0.1.2 → 0.2.0-bech32-address
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/.idea/codeStyles/Project.xml +0 -24
- package/.idea/dbnavigator.xml +4 -6
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +0 -40
- package/.idea/workspace.xml +69 -426
- package/lib/validations.js +3 -0
- package/package.json +1 -1
- package/.idea/encodings.xml +0 -4
- package/.idea/markdown-navigator/profiles_settings.xml +0 -3
- package/.idea/markdown-navigator.xml +0 -86
- package/dist/errors.d.ts +0 -12
- package/dist/errors.js +0 -43
- package/dist/formatting.d.ts +0 -10
- package/dist/formatting.js +0 -25
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -14
- package/dist/middleware.d.ts +0 -8
- package/dist/middleware.js +0 -23
- package/dist/ormHelpers.d.ts +0 -4
- package/dist/ormHelpers.js +0 -25
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -2
- package/dist/types.d.ts +0 -14
- package/dist/types.js +0 -207
- package/dist/validations.d.ts +0 -49
- package/dist/validations.js +0 -242
package/dist/validations.js
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
|
-
if (mod && mod.__esModule) return mod;
|
|
4
|
-
var result = {};
|
|
5
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
-
result["default"] = mod;
|
|
7
|
-
return result;
|
|
8
|
-
};
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
/// <reference path="../node_modules/@types/validator/index.d.ts" />
|
|
14
|
-
const _ = __importStar(require("lodash"));
|
|
15
|
-
const V = __importStar(require("validator"));
|
|
16
|
-
const errors_1 = __importDefault(require("./errors"));
|
|
17
|
-
const { crypto: { Signature }, HDPrivateKey, HDPublicKey, PublicKey, Script, Transaction, } = require('bitcore-lib');
|
|
18
|
-
const addressValidator = require('wallet-address-validator');
|
|
19
|
-
const web3 = require('web3-utils');
|
|
20
|
-
const helpers = {};
|
|
21
|
-
const validations = {
|
|
22
|
-
_validate(Err, pred, x, msg) {
|
|
23
|
-
if (pred(x)) {
|
|
24
|
-
return x;
|
|
25
|
-
}
|
|
26
|
-
throw new Err(msg);
|
|
27
|
-
},
|
|
28
|
-
_validateArg(pred, x, msg) {
|
|
29
|
-
return this._validate(errors_1.default.InvalidArguments, pred, x, msg);
|
|
30
|
-
},
|
|
31
|
-
_tryCheck(fn, arg) {
|
|
32
|
-
try {
|
|
33
|
-
fn(arg);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
exists(x) {
|
|
41
|
-
return x != null;
|
|
42
|
-
},
|
|
43
|
-
argExists(x, msg) {
|
|
44
|
-
return this._validateArg(this.exists, x, msg);
|
|
45
|
-
},
|
|
46
|
-
nonEmpty(x) {
|
|
47
|
-
return (x != null ? x.length : undefined) > 0;
|
|
48
|
-
},
|
|
49
|
-
isNonEmptyString(x) {
|
|
50
|
-
return _.isString(x) && (x != null ? x.length : 0) > 0;
|
|
51
|
-
},
|
|
52
|
-
ensureShortEnough(limit, x) {
|
|
53
|
-
const l = x != null ? x.length : undefined;
|
|
54
|
-
if (l <= limit) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
throw new errors_1.default.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
|
|
58
|
-
},
|
|
59
|
-
ensure(crit, msg) {
|
|
60
|
-
if (crit) {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
throw new errors_1.default.BadRequest(msg);
|
|
64
|
-
},
|
|
65
|
-
check: {
|
|
66
|
-
matches(required, given, msg) {
|
|
67
|
-
given = _.uniq(given);
|
|
68
|
-
const crit = _.intersection(given, required).length === given.length;
|
|
69
|
-
if (crit) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
throw new errors_1.default.BadRequest(msg);
|
|
73
|
-
},
|
|
74
|
-
wasFound(type) {
|
|
75
|
-
return (item) => {
|
|
76
|
-
if (item == null) {
|
|
77
|
-
throw new errors_1.default.NotFound(`Unknown ${type}`);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return item;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
wasCreated(msg) {
|
|
85
|
-
return (arr) => {
|
|
86
|
-
if (!arr[1]) {
|
|
87
|
-
throw new errors_1.default.BadRequest(msg);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return arr;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
},
|
|
94
|
-
isTrue(crit, msg) {
|
|
95
|
-
if (crit) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
throw new errors_1.default.BadRequest(msg);
|
|
99
|
-
},
|
|
100
|
-
isFalse(crit, msg) {
|
|
101
|
-
if (!crit) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
throw new errors_1.default.BadRequest(msg);
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
isCustomerReference(x) {
|
|
108
|
-
return (_.isString(x) &&
|
|
109
|
-
(x != null ? x.length > 0 : false) &&
|
|
110
|
-
(x != null ? x.length <= 100 : false));
|
|
111
|
-
},
|
|
112
|
-
isCustomerLabelName(x) {
|
|
113
|
-
return (_.isString(x) &&
|
|
114
|
-
(x != null ? x.length > 0 : false) &&
|
|
115
|
-
(x != null ? x.length <= 50 : false));
|
|
116
|
-
},
|
|
117
|
-
ethereum: {
|
|
118
|
-
isAddress(str) {
|
|
119
|
-
return web3.isAddress(str);
|
|
120
|
-
},
|
|
121
|
-
isBlockHash(str) {
|
|
122
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
123
|
-
},
|
|
124
|
-
isTxHash(str) {
|
|
125
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
126
|
-
},
|
|
127
|
-
isAddressCode(str) {
|
|
128
|
-
return web3.isHexStrict(str);
|
|
129
|
-
},
|
|
130
|
-
isValidWeiAmount(str) {
|
|
131
|
-
try {
|
|
132
|
-
web3.fromWei(str);
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
bitcoin: {
|
|
141
|
-
isAddress(str) {
|
|
142
|
-
const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'livenet';
|
|
143
|
-
return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
|
|
144
|
-
},
|
|
145
|
-
isHDPublicKey(str) {
|
|
146
|
-
try {
|
|
147
|
-
HDPublicKey(str);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
isPublicKey(str) {
|
|
155
|
-
try {
|
|
156
|
-
PublicKey(str);
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
isTxHash(str) {
|
|
164
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
return str.length === 64;
|
|
168
|
-
},
|
|
169
|
-
isTxHex(str) {
|
|
170
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
Transaction(str);
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
isHDPath(str) {
|
|
182
|
-
return HDPrivateKey.isValidPath(str);
|
|
183
|
-
},
|
|
184
|
-
isScriptHex(str) {
|
|
185
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
Script(str);
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
isTxSignature(str) {
|
|
197
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
const b = Buffer.from(str, 'hex');
|
|
202
|
-
Signature.fromTxFormat(b);
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
},
|
|
209
|
-
isBlockHeight(obj) {
|
|
210
|
-
return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
bitcoinCash: {
|
|
214
|
-
isAddress(str) {
|
|
215
|
-
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);
|
|
216
|
-
},
|
|
217
|
-
isTxHash(str) {
|
|
218
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
return str.length === 64;
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
litecoin: {
|
|
225
|
-
isAddress(str) {
|
|
226
|
-
return /^[3LM][a-km-zA-HJ-NP-Z1-9]{24,33}|^ltc1[ac-hj-np-z02-9]{6,86}|^LTC1[AC-HJ-NP-Z02-9]{6,86}/.test(str);
|
|
227
|
-
},
|
|
228
|
-
isTxHash(str) {
|
|
229
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
return str.length === 64;
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
};
|
|
236
|
-
Object.assign(validations, helpers);
|
|
237
|
-
Object.keys(V).forEach((k) => {
|
|
238
|
-
const v = V[k];
|
|
239
|
-
// don't trigger validation with null values (prevents swagger 500 error)
|
|
240
|
-
validations[k] = (x) => (x === null ? false : v(x));
|
|
241
|
-
});
|
|
242
|
-
exports.default = validations;
|