@ellipticltd/aml-utils 0.2.1 → 0.3.0
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/.circleci/config.yml +47 -0
- package/lib/validations.js +41 -30
- package/package.json +2 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
executors:
|
|
4
|
+
node-8_4:
|
|
5
|
+
docker:
|
|
6
|
+
- image: circleci/node:8.4.0
|
|
7
|
+
working_directory: /tmp/workspace
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
install:
|
|
11
|
+
executor: node-8_4
|
|
12
|
+
steps:
|
|
13
|
+
- checkout
|
|
14
|
+
- restore_cache:
|
|
15
|
+
keys:
|
|
16
|
+
- npm-cache-{{ checksum "package-lock.json" }}
|
|
17
|
+
- run:
|
|
18
|
+
name: install node modules
|
|
19
|
+
command: |
|
|
20
|
+
npm i
|
|
21
|
+
- save_cache:
|
|
22
|
+
key: npm-cache-{{ checksum "package-lock.json" }}
|
|
23
|
+
paths:
|
|
24
|
+
- node_modules
|
|
25
|
+
- persist_to_workspace:
|
|
26
|
+
root: /tmp
|
|
27
|
+
paths:
|
|
28
|
+
- workspace
|
|
29
|
+
|
|
30
|
+
unit_test:
|
|
31
|
+
executor: node-8_4
|
|
32
|
+
steps:
|
|
33
|
+
- attach_workspace:
|
|
34
|
+
at: /tmp
|
|
35
|
+
- run:
|
|
36
|
+
name: unit_test
|
|
37
|
+
command: npm run test
|
|
38
|
+
|
|
39
|
+
workflows:
|
|
40
|
+
version: 2.1
|
|
41
|
+
build-test-deploy:
|
|
42
|
+
jobs:
|
|
43
|
+
- install
|
|
44
|
+
|
|
45
|
+
- unit_test:
|
|
46
|
+
requires:
|
|
47
|
+
- install
|
package/lib/validations.js
CHANGED
|
@@ -112,32 +112,10 @@ const validations = {
|
|
|
112
112
|
(x != null ? x.length : undefined) <= 50
|
|
113
113
|
);
|
|
114
114
|
},
|
|
115
|
-
ethereum: {
|
|
116
|
-
isAddress(str) {
|
|
117
|
-
return web3.isAddress(str);
|
|
118
|
-
},
|
|
119
|
-
isBlockHash(str) {
|
|
120
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
121
|
-
},
|
|
122
|
-
isTxHash(str) {
|
|
123
|
-
return str.length === 66 && web3.isHexStrict(str);
|
|
124
|
-
},
|
|
125
|
-
isAddressCode(str) {
|
|
126
|
-
return web3.isHexStrict(str);
|
|
127
|
-
},
|
|
128
|
-
isValidWeiAmount(str) {
|
|
129
|
-
try {
|
|
130
|
-
web3.fromWei(str);
|
|
131
|
-
return true;
|
|
132
|
-
} catch (e) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
115
|
bitcoin: {
|
|
138
116
|
isAddress(str) {
|
|
139
117
|
const network =
|
|
140
|
-
process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : '
|
|
118
|
+
process.env.BITCOIN_NETWORK === 'testnet' ? 'testnet' : 'prod';
|
|
141
119
|
return typeof str === 'string' && addressValidator.validate(str.trim(), 'BTC', network);
|
|
142
120
|
},
|
|
143
121
|
isBech32Address(str) {
|
|
@@ -160,13 +138,13 @@ const validations = {
|
|
|
160
138
|
}
|
|
161
139
|
},
|
|
162
140
|
isTxHash(str) {
|
|
163
|
-
if (!V.isHexadecimal(
|
|
141
|
+
if (!V.isHexadecimal(str)) {
|
|
164
142
|
return false;
|
|
165
143
|
}
|
|
166
144
|
return str.length === 64;
|
|
167
145
|
},
|
|
168
146
|
isTxHex(str) {
|
|
169
|
-
if (!V.isHexadecimal(
|
|
147
|
+
if (!V.isHexadecimal(str)) {
|
|
170
148
|
return false;
|
|
171
149
|
}
|
|
172
150
|
try {
|
|
@@ -180,7 +158,7 @@ const validations = {
|
|
|
180
158
|
return HDPrivateKey.isValidPath(str);
|
|
181
159
|
},
|
|
182
160
|
isScriptHex(str) {
|
|
183
|
-
if (!V.isHexadecimal(
|
|
161
|
+
if (!V.isHexadecimal(str)) {
|
|
184
162
|
return false;
|
|
185
163
|
}
|
|
186
164
|
try {
|
|
@@ -191,7 +169,7 @@ const validations = {
|
|
|
191
169
|
}
|
|
192
170
|
},
|
|
193
171
|
isTxSignature(str) {
|
|
194
|
-
if (!V.isHexadecimal(
|
|
172
|
+
if (!V.isHexadecimal(str)) {
|
|
195
173
|
return false;
|
|
196
174
|
}
|
|
197
175
|
try {
|
|
@@ -211,23 +189,56 @@ const validations = {
|
|
|
211
189
|
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);
|
|
212
190
|
},
|
|
213
191
|
isTxHash(str) {
|
|
214
|
-
if (!V.isHexadecimal(
|
|
192
|
+
if (!V.isHexadecimal(str)) {
|
|
215
193
|
return false;
|
|
216
194
|
}
|
|
217
195
|
return str.length === 64;
|
|
218
196
|
},
|
|
219
197
|
},
|
|
198
|
+
ethereum: {
|
|
199
|
+
isAddress(str) {
|
|
200
|
+
return web3.isAddress(str);
|
|
201
|
+
},
|
|
202
|
+
isBlockHash(str) {
|
|
203
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
204
|
+
},
|
|
205
|
+
isTxHash(str) {
|
|
206
|
+
return str.length === 66 && web3.isHexStrict(str);
|
|
207
|
+
},
|
|
208
|
+
isAddressCode(str) {
|
|
209
|
+
return web3.isHexStrict(str);
|
|
210
|
+
},
|
|
211
|
+
isValidWeiAmount(str) {
|
|
212
|
+
try {
|
|
213
|
+
web3.fromWei(str);
|
|
214
|
+
return true;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
220
|
litecoin: {
|
|
221
221
|
isAddress(str) {
|
|
222
222
|
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);
|
|
223
223
|
},
|
|
224
224
|
isTxHash(str) {
|
|
225
|
-
if (!V.isHexadecimal(
|
|
225
|
+
if (!V.isHexadecimal(str)) {
|
|
226
226
|
return false;
|
|
227
227
|
}
|
|
228
228
|
return str.length === 64;
|
|
229
229
|
},
|
|
230
|
-
}
|
|
230
|
+
},
|
|
231
|
+
ripple: {
|
|
232
|
+
isAddress(str) {
|
|
233
|
+
return addressValidator.validate(str, 'XRP');
|
|
234
|
+
},
|
|
235
|
+
isTxHash(str) {
|
|
236
|
+
if (!V.isHexadecimal(str)) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return str.length === 64;
|
|
240
|
+
},
|
|
241
|
+
},
|
|
231
242
|
};
|
|
232
243
|
|
|
233
244
|
Object.keys(V).forEach((k) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ellipticltd/aml-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Utilities, helpers, validations, type-checking, etc",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "10.1.0",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"bitcore-lib": "5.0.0-beta.1",
|
|
24
24
|
"create-error": "0.3.1",
|
|
25
|
-
"lodash": "^4.17.
|
|
25
|
+
"lodash": "^4.17.15",
|
|
26
26
|
"type-check": "0.3.2",
|
|
27
27
|
"validator": "10.10.0",
|
|
28
28
|
"wallet-address-validator": "0.2.4",
|