@ellipticltd/aml-utils 0.0.3
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/aml-utils.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +283 -0
- package/dist/errors/errors.d.ts +9 -0
- package/dist/errors/errors.js +42 -0
- package/dist/errors/errors.spec.d.ts +1 -0
- package/dist/errors/errors.spec.js +23 -0
- package/dist/file-parser/__tests/file-parser.spec.d.ts +1 -0
- package/dist/file-parser/__tests/file-parser.spec.js +118 -0
- package/dist/file-parser/__tests/parse-row.spec.d.ts +1 -0
- package/dist/file-parser/__tests/parse-row.spec.js +29 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +1 -0
- package/dist/file-parser/__tests/sanitize-rows.spec.js +78 -0
- package/dist/file-parser/errors.d.ts +3 -0
- package/dist/file-parser/errors.js +11 -0
- package/dist/file-parser/file-parser.d.ts +8 -0
- package/dist/file-parser/file-parser.js +68 -0
- package/dist/file-parser/parse-row.d.ts +2 -0
- package/dist/file-parser/parse-row.js +39 -0
- package/dist/file-parser/sanitzeRows.d.ts +3 -0
- package/dist/file-parser/sanitzeRows.js +18 -0
- package/dist/formatting/formatting.d.ts +2 -0
- package/dist/formatting/formatting.js +17 -0
- package/dist/formatting/formatting.spec.d.ts +1 -0
- package/dist/formatting/formatting.spec.js +37 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/middleware/middleware.d.ts +4 -0
- package/dist/middleware/middleware.js +22 -0
- package/dist/orm-helpers/ormHelpers.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.js +17 -0
- package/dist/orm-helpers/ormHelpers.spec.d.ts +1 -0
- package/dist/orm-helpers/ormHelpers.spec.js +38 -0
- package/dist/types/types.d.ts +17 -0
- package/dist/types/types.js +203 -0
- package/dist/validations/old.validations.d.ts +5 -0
- package/dist/validations/old.validations.js +303 -0
- package/dist/validations/validations.d.ts +118 -0
- package/dist/validations/validations.js +300 -0
- package/dist/validations/validations.spec.d.ts +1 -0
- package/dist/validations/validations.spec.js +287 -0
- package/index.js +12 -0
- package/lib/errors.js +51 -0
- package/lib/formatting.js +28 -0
- package/lib/middleware.js +33 -0
- package/lib/ormHelpers.js +28 -0
- package/lib/types.js +179 -0
- package/lib/validations.js +199 -0
- package/package.json +25 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Generated by CoffeeScript 1.10.0
|
|
2
|
+
(function() {
|
|
3
|
+
var Address, E, HDPrivateKey, HDPublicKey, PublicKey, Script, Signature, Transaction, V, _, k, ref, ref1, v, validations;
|
|
4
|
+
|
|
5
|
+
E = require('./errors');
|
|
6
|
+
|
|
7
|
+
V = require('validator');
|
|
8
|
+
|
|
9
|
+
_ = require('lodash');
|
|
10
|
+
|
|
11
|
+
ref = require('bitcore-lib'), (ref1 = ref.crypto, Signature = ref1.Signature), Address = ref.Address, HDPrivateKey = ref.HDPrivateKey, HDPublicKey = ref.HDPublicKey, PublicKey = ref.PublicKey, Script = ref.Script, Transaction = ref.Transaction;
|
|
12
|
+
|
|
13
|
+
validations = {
|
|
14
|
+
_validate: function(err, pred, x, msg) {
|
|
15
|
+
if (pred(x)) {
|
|
16
|
+
return x;
|
|
17
|
+
} else {
|
|
18
|
+
throw new err(msg);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
_validateArg: function(pred, x, msg) {
|
|
22
|
+
return this._validate(E.InvalidArguments, pred, x, msg);
|
|
23
|
+
},
|
|
24
|
+
_tryCheck: function(fn, arg) {
|
|
25
|
+
var error;
|
|
26
|
+
try {
|
|
27
|
+
fn(arg);
|
|
28
|
+
return true;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
exists: function(x) {
|
|
34
|
+
return x != null;
|
|
35
|
+
},
|
|
36
|
+
nonEmpty: function(x) {
|
|
37
|
+
return (x != null ? x.length : void 0) > 0;
|
|
38
|
+
},
|
|
39
|
+
isNonEmptyString: function(x) {
|
|
40
|
+
return _.isString(x) && (x != null ? x.length : void 0) > 0;
|
|
41
|
+
},
|
|
42
|
+
ensureShortEnough: function(limit, x) {
|
|
43
|
+
var l;
|
|
44
|
+
l = x != null ? x.length : void 0;
|
|
45
|
+
if (l <= limit) {
|
|
46
|
+
return true;
|
|
47
|
+
} else {
|
|
48
|
+
throw new E.BadRequest("Max query size exceeded: " + l + " / " + limit);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
ensure: function(crit, msg) {
|
|
52
|
+
if (crit) {
|
|
53
|
+
return true;
|
|
54
|
+
} else {
|
|
55
|
+
throw new E.BadRequest(msg);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
argExists: function(x, msg) {
|
|
59
|
+
return this._validateArg(this.exists, x, msg);
|
|
60
|
+
},
|
|
61
|
+
check: {
|
|
62
|
+
matches: function(required, given, msg) {
|
|
63
|
+
var crit;
|
|
64
|
+
given = _.uniq(given);
|
|
65
|
+
crit = _.intersection(given, required).length === given.length;
|
|
66
|
+
if (crit) {
|
|
67
|
+
return true;
|
|
68
|
+
} else {
|
|
69
|
+
throw new E.BadRequest(msg);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
wasFound: function(type) {
|
|
73
|
+
return function(item) {
|
|
74
|
+
if (item == null) {
|
|
75
|
+
throw new E.NotFound("Unknown " + type);
|
|
76
|
+
} else {
|
|
77
|
+
return item;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
wasCreated: function(msg) {
|
|
82
|
+
return function(arr) {
|
|
83
|
+
if (!arr[1]) {
|
|
84
|
+
throw new E.BadRequest(msg);
|
|
85
|
+
} else {
|
|
86
|
+
return arr;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
isTrue: function(crit, msg) {
|
|
91
|
+
if (crit) {
|
|
92
|
+
return true;
|
|
93
|
+
} else {
|
|
94
|
+
throw new E.BadRequest(msg);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
isFalse: function(crit, msg) {
|
|
98
|
+
if (!crit) {
|
|
99
|
+
return true;
|
|
100
|
+
} else {
|
|
101
|
+
throw new E.BadRequest(msg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
isCustomerReference: function(x) {
|
|
106
|
+
return _.isString(x) && (x != null ? x.length : void 0) > 0 && (x != null ? x.length : void 0) <= 100;
|
|
107
|
+
},
|
|
108
|
+
isCustomerLabelName: function(x) {
|
|
109
|
+
return _.isString(x) && (x != null ? x.length : void 0) > 0 && (x != null ? x.length : void 0) <= 50;
|
|
110
|
+
},
|
|
111
|
+
bitcoin: {
|
|
112
|
+
isAddress: function(str) {
|
|
113
|
+
var error, network;
|
|
114
|
+
network = process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'livenet';
|
|
115
|
+
try {
|
|
116
|
+
Address(str, network);
|
|
117
|
+
return true;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
isHDPublicKey: function(str) {
|
|
123
|
+
var error;
|
|
124
|
+
try {
|
|
125
|
+
HDPublicKey(str);
|
|
126
|
+
return true;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
isPublicKey: function(str) {
|
|
132
|
+
var error;
|
|
133
|
+
try {
|
|
134
|
+
PublicKey(str);
|
|
135
|
+
return true;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
isTxHash: function(str) {
|
|
141
|
+
if (!V.isHexadecimal(str + '')) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return str.length === 64;
|
|
145
|
+
},
|
|
146
|
+
isTxHex: function(str) {
|
|
147
|
+
var error;
|
|
148
|
+
if (!V.isHexadecimal(str + '')) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
Transaction(str);
|
|
153
|
+
return true;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
isHDPath: function(str) {
|
|
159
|
+
return HDPrivateKey.isValidPath(str);
|
|
160
|
+
},
|
|
161
|
+
isScriptHex: function(str) {
|
|
162
|
+
var error;
|
|
163
|
+
if (!V.isHexadecimal(str + '')) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
Script(str);
|
|
168
|
+
return true;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
isTxSignature: function(str) {
|
|
174
|
+
var b, error;
|
|
175
|
+
if (!V.isHexadecimal(str + '')) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
b = new Buffer(str, 'hex');
|
|
180
|
+
Signature.fromTxFormat(b);
|
|
181
|
+
return true;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
isBlockHeight: function(obj) {
|
|
187
|
+
return _.isInteger(+obj) && parseInt(obj) >= 0;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
for (k in V) {
|
|
193
|
+
v = V[k];
|
|
194
|
+
validations[k] = v;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
module.exports = validations;
|
|
198
|
+
|
|
199
|
+
}).call(this);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ellipticltd/aml-utils",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Utilities, helpers, validations, type-checking, etc",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "./node_modules/.bin/mocha --reporter spec --compilers coffee:coffee-script/register --require 'test/index.coffee'",
|
|
8
|
+
"compile": "./node_modules/coffee-script/bin/coffee -c index.coffee **/*.coffee",
|
|
9
|
+
"preprocess": "npm run compile"
|
|
10
|
+
},
|
|
11
|
+
"author": "Adam Joyce <adam@ellipitc.co>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"bitcore-lib": "0.13.19",
|
|
15
|
+
"create-error": "0.3.1",
|
|
16
|
+
"lodash": "4.14.2",
|
|
17
|
+
"type-check": "0.3.2",
|
|
18
|
+
"validator": "5.5.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"chai": "^3.5.0",
|
|
22
|
+
"coffee-script": "1.10.0",
|
|
23
|
+
"mocha": "^3.0.2"
|
|
24
|
+
}
|
|
25
|
+
}
|