@ellipticltd/aml-utils 0.1.1-ts.3 → 0.1.1
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/.npmignore +4 -0
- package/index.d.ts +1 -0
- package/index.js +8 -0
- package/lib/errors.js +53 -0
- package/lib/formatting.js +18 -0
- package/lib/middleware.js +25 -0
- package/lib/ormHelpers.js +19 -0
- package/lib/types.js +211 -0
- package/lib/validations.js +236 -0
- package/package.json +5 -15
- package/.idea/aml-utils.iml +0 -12
- package/.idea/codeStyles/Project.xml +0 -52
- package/.idea/dbnavigator.xml +0 -456
- package/.idea/encodings.xml +0 -4
- package/.idea/markdown-navigator/profiles_settings.xml +0 -3
- package/.idea/markdown-navigator.xml +0 -86
- package/.idea/misc.xml +0 -46
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -558
- package/dist/errors.d.ts +0 -9
- package/dist/errors.js +0 -32
- package/dist/formatting.d.ts +0 -10
- package/dist/formatting.js +0 -25
- package/dist/index.d.ts +0 -81
- package/dist/index.js +0 -27
- 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 -239
- package/tsconfig.json +0 -80
- package/tslint.json +0 -18
package/dist/index.d.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as errors from "./errors";
|
|
2
|
-
declare const amlUtils: {
|
|
3
|
-
types: {
|
|
4
|
-
parseType(str: any): any;
|
|
5
|
-
parsedTypeCheck(type: any, obj: any): any;
|
|
6
|
-
typeCheck(type: any, obj: any): any;
|
|
7
|
-
opts: {
|
|
8
|
-
customTypes: {};
|
|
9
|
-
};
|
|
10
|
-
ensureType(type: any, obj: any, msg: string): any;
|
|
11
|
-
checkArg(obj: any, prop: any, type: any, msg: string): any;
|
|
12
|
-
checkArgs(input: {
|
|
13
|
-
[K: string]: any;
|
|
14
|
-
}, types: any[]): void;
|
|
15
|
-
};
|
|
16
|
-
validations: {
|
|
17
|
-
_validate: (Err: new (msg: string) => Error, pred: (x: any) => boolean, x: any, msg: string) => any;
|
|
18
|
-
_validateArg: (pred: (x: any) => boolean, x: any, msg: string) => any;
|
|
19
|
-
_tryCheck: (fn: (arg: any) => any, arg: any) => boolean;
|
|
20
|
-
exists: (x: any) => boolean;
|
|
21
|
-
argExists: (x: any, msg: string) => boolean;
|
|
22
|
-
nonEmpty: (...args: any) => any;
|
|
23
|
-
isNonEmptyString: (...args: any) => any;
|
|
24
|
-
ensureShortEnough: (...args: any) => any;
|
|
25
|
-
ensure: (...args: any) => any;
|
|
26
|
-
check: {
|
|
27
|
-
matches: (...args: any) => any;
|
|
28
|
-
wasFound: (...args: any) => any;
|
|
29
|
-
wasCreated: (...args: any) => any;
|
|
30
|
-
isTrue: (...args: any) => any;
|
|
31
|
-
isFalse: (...args: any) => any;
|
|
32
|
-
};
|
|
33
|
-
isCustomerReference: (...args: any) => any;
|
|
34
|
-
isCustomerLabelName: (...args: any) => any;
|
|
35
|
-
ethereum: {
|
|
36
|
-
isAddress: (...args: any) => any;
|
|
37
|
-
isBlockHash: (...args: any) => any;
|
|
38
|
-
isTxHash: (...args: any) => any;
|
|
39
|
-
isAddressCode: (...args: any) => any;
|
|
40
|
-
isValidWeiAmount: (...args: any) => any;
|
|
41
|
-
};
|
|
42
|
-
bitcoin: {
|
|
43
|
-
isAddress: (...args: any) => any;
|
|
44
|
-
isHDPublicKey: (...args: any) => any;
|
|
45
|
-
isPublicKey: (...args: any) => any;
|
|
46
|
-
isTxHash: (...args: any) => any;
|
|
47
|
-
isTxHex: (...args: any) => any;
|
|
48
|
-
isHDPath: (...args: any) => any;
|
|
49
|
-
isScriptHex: (...args: any) => any;
|
|
50
|
-
isTxSignature: (...args: any) => any;
|
|
51
|
-
isBlockHeight: (...args: any) => any;
|
|
52
|
-
};
|
|
53
|
-
bitcoinCash: {
|
|
54
|
-
isAddress: (...args: any) => any;
|
|
55
|
-
isTxHash: (...args: any) => any;
|
|
56
|
-
};
|
|
57
|
-
litecoin: {
|
|
58
|
-
isAddress: (...args: any) => any;
|
|
59
|
-
isTxHash: (...args: any) => any;
|
|
60
|
-
};
|
|
61
|
-
} & IValidatorStatic;
|
|
62
|
-
errors: typeof errors;
|
|
63
|
-
formatting: {
|
|
64
|
-
rethrowError: (fnName: string, e: {
|
|
65
|
-
error: Error | Error[];
|
|
66
|
-
statusCode: number;
|
|
67
|
-
name: string;
|
|
68
|
-
}) => string;
|
|
69
|
-
sqlEscapeWildcard: (str: string) => string;
|
|
70
|
-
};
|
|
71
|
-
middleware: {
|
|
72
|
-
ensureType: (type: string) => (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction, id: any, name: string) => void;
|
|
73
|
-
ensureUUID: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction, id: any, name: string) => void;
|
|
74
|
-
ensureHex32: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction, id: any, name: string) => void;
|
|
75
|
-
ensureInteger: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction, id: any, name: string) => void;
|
|
76
|
-
};
|
|
77
|
-
ormHelpers: {
|
|
78
|
-
includeNested: (orm: any, models: any) => any;
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
export default amlUtils;
|
package/dist/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
6
|
-
if (mod && mod.__esModule) return mod;
|
|
7
|
-
var result = {};
|
|
8
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
9
|
-
result["default"] = mod;
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
const types_1 = __importDefault(require("./types"));
|
|
14
|
-
const validations_1 = __importDefault(require("./validations"));
|
|
15
|
-
const errors = __importStar(require("./errors"));
|
|
16
|
-
const formatting_1 = __importDefault(require("./formatting"));
|
|
17
|
-
const middleware_1 = __importDefault(require("./middleware"));
|
|
18
|
-
const ormHelpers_1 = __importDefault(require("./ormHelpers"));
|
|
19
|
-
const amlUtils = {
|
|
20
|
-
types: types_1.default,
|
|
21
|
-
validations: validations_1.default,
|
|
22
|
-
errors,
|
|
23
|
-
formatting: formatting_1.default,
|
|
24
|
-
middleware: middleware_1.default,
|
|
25
|
-
ormHelpers: ormHelpers_1.default,
|
|
26
|
-
};
|
|
27
|
-
exports.default = amlUtils;
|
package/dist/middleware.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
ensureType: (type: string) => (req: Request, res: Response, next: NextFunction, id: any, name: string) => void;
|
|
4
|
-
ensureUUID: (req: Request, res: Response, next: NextFunction, id: any, name: string) => void;
|
|
5
|
-
ensureHex32: (req: Request, res: Response, next: NextFunction, id: any, name: string) => void;
|
|
6
|
-
ensureInteger: (req: Request, res: Response, next: NextFunction, id: any, name: string) => void;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
package/dist/middleware.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const T = require('./types');
|
|
4
|
-
const ensureType = (type) => (req, res, next, id, name) => {
|
|
5
|
-
let error;
|
|
6
|
-
try {
|
|
7
|
-
T.ensureType(type, id, `Invalid ${name}`);
|
|
8
|
-
return next();
|
|
9
|
-
}
|
|
10
|
-
catch (error1) {
|
|
11
|
-
error = error1;
|
|
12
|
-
return next(error);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const ensureUUID = ensureType('UUID');
|
|
16
|
-
const ensureHex32 = ensureType('Hex32');
|
|
17
|
-
const ensureInteger = ensureType('IntString');
|
|
18
|
-
exports.default = {
|
|
19
|
-
ensureType,
|
|
20
|
-
ensureUUID,
|
|
21
|
-
ensureHex32,
|
|
22
|
-
ensureInteger,
|
|
23
|
-
};
|
package/dist/ormHelpers.d.ts
DELETED
package/dist/ormHelpers.js
DELETED
|
@@ -1,25 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
const _ = __importStar(require("lodash"));
|
|
11
|
-
const includeNested = (orm, models) => _.map(_.toPairs(models), (arg) => {
|
|
12
|
-
const [modelName, inclusion] = arg;
|
|
13
|
-
const include = includeNested(orm, inclusion);
|
|
14
|
-
const model = orm[modelName];
|
|
15
|
-
if (_.isEmpty(include)) {
|
|
16
|
-
return model;
|
|
17
|
-
}
|
|
18
|
-
return {
|
|
19
|
-
model,
|
|
20
|
-
include,
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
exports.default = {
|
|
24
|
-
includeNested,
|
|
25
|
-
};
|
package/dist/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test.js
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
parseType(str: any): any;
|
|
3
|
-
parsedTypeCheck(type: any, obj: any): any;
|
|
4
|
-
typeCheck(type: any, obj: any): any;
|
|
5
|
-
opts: {
|
|
6
|
-
customTypes: {};
|
|
7
|
-
};
|
|
8
|
-
ensureType(type: any, obj: any, msg: string): any;
|
|
9
|
-
checkArg(obj: any, prop: any, type: any, msg: string): any;
|
|
10
|
-
checkArgs(input: {
|
|
11
|
-
[K: string]: any;
|
|
12
|
-
}, types: any[]): void;
|
|
13
|
-
};
|
|
14
|
-
export default _default;
|
package/dist/types.js
DELETED
|
@@ -1,207 +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
|
-
// @ts-ignore
|
|
14
|
-
const TC = __importStar(require("type-check"));
|
|
15
|
-
const _ = __importStar(require("lodash"));
|
|
16
|
-
const validations_1 = __importDefault(require("./validations"));
|
|
17
|
-
const E = __importStar(require("./errors"));
|
|
18
|
-
const customTypes = {
|
|
19
|
-
Integer: {
|
|
20
|
-
typeOf: 'Number',
|
|
21
|
-
validate(x) {
|
|
22
|
-
return x % 1 === 0;
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
IntString: {
|
|
26
|
-
typeOf: 'String',
|
|
27
|
-
validate: validations_1.default.isInt,
|
|
28
|
-
},
|
|
29
|
-
BoolString: {
|
|
30
|
-
typeOf: 'String',
|
|
31
|
-
validate: validations_1.default.isBoolean,
|
|
32
|
-
},
|
|
33
|
-
Hex32: {
|
|
34
|
-
typeOf: 'String',
|
|
35
|
-
validate(x) {
|
|
36
|
-
return validations_1.default.isHexadecimal(x) && x.length === 32;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
Email: {
|
|
40
|
-
typeOf: 'String',
|
|
41
|
-
validate: validations_1.default.isEmail,
|
|
42
|
-
},
|
|
43
|
-
UUID: {
|
|
44
|
-
typeOf: 'String',
|
|
45
|
-
validate: validations_1.default.isUUID,
|
|
46
|
-
},
|
|
47
|
-
UUIDv4: {
|
|
48
|
-
typeOf: 'String',
|
|
49
|
-
validate(x) {
|
|
50
|
-
return validations_1.default.isUUID(x, 4);
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
JSON: {
|
|
54
|
-
typeOf: 'String',
|
|
55
|
-
validate: validations_1.default.isJSON,
|
|
56
|
-
},
|
|
57
|
-
Url: {
|
|
58
|
-
typeOf: 'String',
|
|
59
|
-
validate: validations_1.default.isURL,
|
|
60
|
-
},
|
|
61
|
-
NonEmptyArray: {
|
|
62
|
-
typeOf: 'Array',
|
|
63
|
-
validate: validations_1.default.nonEmpty,
|
|
64
|
-
},
|
|
65
|
-
NonNullString: {
|
|
66
|
-
typeOf: 'String',
|
|
67
|
-
validate: validations_1.default.nonEmpty,
|
|
68
|
-
},
|
|
69
|
-
CustomerReference: {
|
|
70
|
-
typeOf: 'String',
|
|
71
|
-
validate: validations_1.default.isCustomerReference,
|
|
72
|
-
},
|
|
73
|
-
CustomerLabelName: {
|
|
74
|
-
typeOf: 'String',
|
|
75
|
-
validate: validations_1.default.isCustomerLabelName,
|
|
76
|
-
},
|
|
77
|
-
BitcoinAddress: {
|
|
78
|
-
typeOf: 'String',
|
|
79
|
-
validate: validations_1.default.bitcoin.isAddress,
|
|
80
|
-
},
|
|
81
|
-
EthereumAddress: {
|
|
82
|
-
typeOf: 'String',
|
|
83
|
-
validate: validations_1.default.ethereum.isAddress,
|
|
84
|
-
},
|
|
85
|
-
EthereumTx: {
|
|
86
|
-
typeOf: 'String',
|
|
87
|
-
validate: validations_1.default.ethereum.isTxHash,
|
|
88
|
-
},
|
|
89
|
-
EthereumBlockHash: {
|
|
90
|
-
typeOf: 'String',
|
|
91
|
-
validate: validations_1.default.ethereum.isBlockHash,
|
|
92
|
-
},
|
|
93
|
-
EthereumWeiAmount: {
|
|
94
|
-
typeOf: 'String',
|
|
95
|
-
validate: validations_1.default.ethereum.isValidWeiAmount,
|
|
96
|
-
},
|
|
97
|
-
EthereumAddressCode: {
|
|
98
|
-
typeOf: 'String',
|
|
99
|
-
validate: validations_1.default.ethereum.isAddressCode,
|
|
100
|
-
},
|
|
101
|
-
MineId: {
|
|
102
|
-
typeOf: 'String',
|
|
103
|
-
validate(x) {
|
|
104
|
-
return x === 'mine';
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
BitcoinTxHash: {
|
|
108
|
-
typeOf: 'String',
|
|
109
|
-
validate: validations_1.default.bitcoin.isTxHash,
|
|
110
|
-
},
|
|
111
|
-
BitcoinAddressArray: {
|
|
112
|
-
typeOf: 'Array',
|
|
113
|
-
validate(as) {
|
|
114
|
-
return _.every(as, validations_1.default.bitcoin.isAddress);
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
BitcoinTxHashArray: {
|
|
118
|
-
typeOf: 'Array',
|
|
119
|
-
validate(as) {
|
|
120
|
-
return _.every(as, validations_1.default.bitcoin.isTxHash);
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
BitcoinTxHex: {
|
|
124
|
-
typeOf: 'String',
|
|
125
|
-
validate: validations_1.default.bitcoin.isTxHex,
|
|
126
|
-
},
|
|
127
|
-
BitcoinScriptHex: {
|
|
128
|
-
typeOf: 'String',
|
|
129
|
-
validate: validations_1.default.bitcoin.isScriptHex,
|
|
130
|
-
},
|
|
131
|
-
BitcoinHDPath: {
|
|
132
|
-
typeOf: 'String',
|
|
133
|
-
validate: validations_1.default.bitcoin.isHDPath,
|
|
134
|
-
},
|
|
135
|
-
BitcoinPublicKey: {
|
|
136
|
-
typeOf: 'String',
|
|
137
|
-
validate: validations_1.default.bitcoin.isPublicKey,
|
|
138
|
-
},
|
|
139
|
-
BitcoinXpub: {
|
|
140
|
-
typeOf: 'String',
|
|
141
|
-
validate: validations_1.default.bitcoin.isHDPublicKey,
|
|
142
|
-
},
|
|
143
|
-
BitcoinTxSignature: {
|
|
144
|
-
typeOf: 'String',
|
|
145
|
-
validate: validations_1.default.bitcoin.isTxSignature,
|
|
146
|
-
},
|
|
147
|
-
BitcoinBlockHeight: {
|
|
148
|
-
typeOf: 'Number',
|
|
149
|
-
validate: validations_1.default.bitcoin.isBlockHeight,
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
// add support for nullable properties
|
|
153
|
-
const withNullable = Object.keys(customTypes).reduce((acc, _type) => {
|
|
154
|
-
acc[_type] = customTypes[_type];
|
|
155
|
-
const { typeOf, validate } = customTypes[_type];
|
|
156
|
-
// for every type, add Nullable+type. A nullable string can also be empty
|
|
157
|
-
acc[`Nullable${_type}`] = Object.assign({}, customTypes[_type], {
|
|
158
|
-
validate: (x) => x == null || (typeOf === 'String' && x === '') || validate(x),
|
|
159
|
-
});
|
|
160
|
-
return acc;
|
|
161
|
-
}, {});
|
|
162
|
-
exports.default = {
|
|
163
|
-
parseType(str) {
|
|
164
|
-
return TC.parseType(str);
|
|
165
|
-
},
|
|
166
|
-
parsedTypeCheck(type, obj) {
|
|
167
|
-
return TC.parsedTypeCheck(type, obj, this.opts);
|
|
168
|
-
},
|
|
169
|
-
typeCheck(type, obj) {
|
|
170
|
-
return TC.typeCheck(type, obj, this.opts);
|
|
171
|
-
},
|
|
172
|
-
opts: {
|
|
173
|
-
customTypes: withNullable,
|
|
174
|
-
},
|
|
175
|
-
ensureType(type, obj, msg) {
|
|
176
|
-
return validations_1.default.ensure(this.typeCheck(type, obj), msg);
|
|
177
|
-
},
|
|
178
|
-
checkArg(obj, prop, type, msg) {
|
|
179
|
-
if (msg == null) {
|
|
180
|
-
msg = `Invalid ${prop}`;
|
|
181
|
-
}
|
|
182
|
-
this.ensureType(type, obj[prop], msg);
|
|
183
|
-
return obj[prop];
|
|
184
|
-
},
|
|
185
|
-
checkArgs(input, types) {
|
|
186
|
-
const inputKeys = {};
|
|
187
|
-
const [typ] = types;
|
|
188
|
-
const fields = typ.of;
|
|
189
|
-
let numInputKeys = 0;
|
|
190
|
-
let numKeys;
|
|
191
|
-
Object.keys(input).forEach((k) => {
|
|
192
|
-
inputKeys[k] = true;
|
|
193
|
-
numInputKeys += 1;
|
|
194
|
-
});
|
|
195
|
-
numKeys = 0;
|
|
196
|
-
Object.keys(fields).forEach((key) => {
|
|
197
|
-
types = fields[key];
|
|
198
|
-
validations_1.default.ensure(this.parsedTypeCheck(types, input[key]), `Invalid ${key}`);
|
|
199
|
-
if (inputKeys[key]) {
|
|
200
|
-
numKeys += 1;
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
if (!(typ.subset || numInputKeys === numKeys)) {
|
|
204
|
-
throw new E.BadRequest('invalid extra arguments are present');
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
};
|
package/dist/validations.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
declare type ValidatorFunction = (...args: any) => any;
|
|
2
|
-
declare type Validations = {
|
|
3
|
-
_validate: (Err: new (msg: string) => Error, pred: (x: any) => boolean, x: any, msg: string) => any;
|
|
4
|
-
_validateArg: (pred: (x: any) => boolean, x: any, msg: string) => any;
|
|
5
|
-
_tryCheck: (fn: (arg: any) => any, arg: any) => boolean;
|
|
6
|
-
exists: (x: any) => boolean;
|
|
7
|
-
argExists: (x: any, msg: string) => boolean;
|
|
8
|
-
nonEmpty: ValidatorFunction;
|
|
9
|
-
isNonEmptyString: ValidatorFunction;
|
|
10
|
-
ensureShortEnough: ValidatorFunction;
|
|
11
|
-
ensure: ValidatorFunction;
|
|
12
|
-
check: {
|
|
13
|
-
matches: ValidatorFunction;
|
|
14
|
-
wasFound: ValidatorFunction;
|
|
15
|
-
wasCreated: ValidatorFunction;
|
|
16
|
-
isTrue: ValidatorFunction;
|
|
17
|
-
isFalse: ValidatorFunction;
|
|
18
|
-
};
|
|
19
|
-
isCustomerReference: ValidatorFunction;
|
|
20
|
-
isCustomerLabelName: ValidatorFunction;
|
|
21
|
-
ethereum: {
|
|
22
|
-
isAddress: ValidatorFunction;
|
|
23
|
-
isBlockHash: ValidatorFunction;
|
|
24
|
-
isTxHash: ValidatorFunction;
|
|
25
|
-
isAddressCode: ValidatorFunction;
|
|
26
|
-
isValidWeiAmount: ValidatorFunction;
|
|
27
|
-
};
|
|
28
|
-
bitcoin: {
|
|
29
|
-
isAddress: ValidatorFunction;
|
|
30
|
-
isHDPublicKey: ValidatorFunction;
|
|
31
|
-
isPublicKey: ValidatorFunction;
|
|
32
|
-
isTxHash: ValidatorFunction;
|
|
33
|
-
isTxHex: ValidatorFunction;
|
|
34
|
-
isHDPath: ValidatorFunction;
|
|
35
|
-
isScriptHex: ValidatorFunction;
|
|
36
|
-
isTxSignature: ValidatorFunction;
|
|
37
|
-
isBlockHeight: ValidatorFunction;
|
|
38
|
-
};
|
|
39
|
-
bitcoinCash: {
|
|
40
|
-
isAddress: ValidatorFunction;
|
|
41
|
-
isTxHash: ValidatorFunction;
|
|
42
|
-
};
|
|
43
|
-
litecoin: {
|
|
44
|
-
isAddress: ValidatorFunction;
|
|
45
|
-
isTxHash: ValidatorFunction;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
declare const _default: Validations & IValidatorStatic;
|
|
49
|
-
export default _default;
|
package/dist/validations.js
DELETED
|
@@ -1,239 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
/// <reference path="../node_modules/@types/validator/index.d.ts" />
|
|
11
|
-
const _ = __importStar(require("lodash"));
|
|
12
|
-
const V = __importStar(require("validator"));
|
|
13
|
-
const E = __importStar(require("./errors"));
|
|
14
|
-
const { crypto: { Signature }, HDPrivateKey, HDPublicKey, PublicKey, Script, Transaction, } = require('bitcore-lib');
|
|
15
|
-
const addressValidator = require('wallet-address-validator');
|
|
16
|
-
const web3 = require('web3-utils');
|
|
17
|
-
const helpers = {};
|
|
18
|
-
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
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
exists(x) {
|
|
38
|
-
return x != null;
|
|
39
|
-
},
|
|
40
|
-
argExists(x, msg) {
|
|
41
|
-
return this._validateArg(this.exists, x, msg);
|
|
42
|
-
},
|
|
43
|
-
nonEmpty(x) {
|
|
44
|
-
return (x != null ? x.length : undefined) > 0;
|
|
45
|
-
},
|
|
46
|
-
isNonEmptyString(x) {
|
|
47
|
-
return _.isString(x) && (x != null ? x.length : 0) > 0;
|
|
48
|
-
},
|
|
49
|
-
ensureShortEnough(limit, x) {
|
|
50
|
-
const l = x != null ? x.length : undefined;
|
|
51
|
-
if (l <= limit) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
throw new E.BadRequest(`Max query size exceeded: ${l} / ${limit}`);
|
|
55
|
-
},
|
|
56
|
-
ensure(crit, msg) {
|
|
57
|
-
if (crit) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
throw new E.BadRequest(msg);
|
|
61
|
-
},
|
|
62
|
-
check: {
|
|
63
|
-
matches(required, given, msg) {
|
|
64
|
-
given = _.uniq(given);
|
|
65
|
-
const crit = _.intersection(given, 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) &&
|
|
106
|
-
(x != null ? x.length > 0 : false) &&
|
|
107
|
-
(x != null ? x.length <= 100 : false));
|
|
108
|
-
},
|
|
109
|
-
isCustomerLabelName(x) {
|
|
110
|
-
return (_.isString(x) &&
|
|
111
|
-
(x != null ? x.length > 0 : false) &&
|
|
112
|
-
(x != null ? x.length <= 50 : false));
|
|
113
|
-
},
|
|
114
|
-
ethereum: {
|
|
115
|
-
isAddress(str) {
|
|
116
|
-
return web3.isAddress(str);
|
|
117
|
-
},
|
|
118
|
-
isBlockHash(str) {
|
|
119
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
120
|
-
},
|
|
121
|
-
isTxHash(str) {
|
|
122
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
123
|
-
},
|
|
124
|
-
isAddressCode(str) {
|
|
125
|
-
return web3.isHexStrict(str);
|
|
126
|
-
},
|
|
127
|
-
isValidWeiAmount(str) {
|
|
128
|
-
try {
|
|
129
|
-
web3.fromWei(str);
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
bitcoin: {
|
|
138
|
-
isAddress(str) {
|
|
139
|
-
const network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'livenet';
|
|
140
|
-
return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
|
|
141
|
-
},
|
|
142
|
-
isHDPublicKey(str) {
|
|
143
|
-
try {
|
|
144
|
-
HDPublicKey(str);
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
isPublicKey(str) {
|
|
152
|
-
try {
|
|
153
|
-
PublicKey(str);
|
|
154
|
-
return true;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
isTxHash(str) {
|
|
161
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
return str.length === 64;
|
|
165
|
-
},
|
|
166
|
-
isTxHex(str) {
|
|
167
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
try {
|
|
171
|
-
Transaction(str);
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
isHDPath(str) {
|
|
179
|
-
return HDPrivateKey.isValidPath(str);
|
|
180
|
-
},
|
|
181
|
-
isScriptHex(str) {
|
|
182
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
Script(str);
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
catch (error) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
isTxSignature(str) {
|
|
194
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
const b = Buffer.from(str, 'hex');
|
|
199
|
-
Signature.fromTxFormat(b);
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
isBlockHeight(obj) {
|
|
207
|
-
return _.isInteger(+obj) && parseInt(obj, 10) >= 0;
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
bitcoinCash: {
|
|
211
|
-
isAddress(str) {
|
|
212
|
-
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);
|
|
213
|
-
},
|
|
214
|
-
isTxHash(str) {
|
|
215
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
return str.length === 64;
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
litecoin: {
|
|
222
|
-
isAddress(str) {
|
|
223
|
-
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);
|
|
224
|
-
},
|
|
225
|
-
isTxHash(str) {
|
|
226
|
-
if (!V.isHexadecimal(`${str}`)) {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
return str.length === 64;
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
Object.assign(validations, helpers);
|
|
234
|
-
Object.keys(V).forEach((k) => {
|
|
235
|
-
const v = V[k];
|
|
236
|
-
// don't trigger validation with null values (prevents swagger 500 error)
|
|
237
|
-
validations[k] = (x) => (x === null ? false : v(x));
|
|
238
|
-
});
|
|
239
|
-
exports.default = validations;
|