@ellipticltd/aml-utils 0.16.27 → 0.16.29

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.
Files changed (99) hide show
  1. package/README.md +11 -43
  2. package/lib/errors/errors.js +19 -30
  3. package/lib/errors/errors.js.map +1 -0
  4. package/{dist → lib}/file-parser/errors.js +1 -1
  5. package/lib/file-parser/errors.js.map +1 -0
  6. package/{dist → lib}/file-parser/file-parser.d.ts +2 -4
  7. package/lib/file-parser/file-parser.js +59 -0
  8. package/lib/file-parser/file-parser.js.map +1 -0
  9. package/{dist/structured-file-parser → lib/file-parser}/parse-row.js +2 -1
  10. package/lib/file-parser/parse-row.js.map +1 -0
  11. package/{dist/file-parser/sanitzeRows.d.ts → lib/file-parser/sanitizeRows.d.ts} +3 -1
  12. package/lib/file-parser/sanitizeRows.js +15 -0
  13. package/lib/file-parser/sanitizeRows.js.map +1 -0
  14. package/lib/formatting/formatting.js +11 -12
  15. package/lib/formatting/formatting.js.map +1 -0
  16. package/{dist → lib}/index.d.ts +1 -1
  17. package/lib/index.js +21 -0
  18. package/lib/index.js.map +1 -0
  19. package/lib/middleware/middleware.js +14 -17
  20. package/lib/middleware/middleware.js.map +1 -0
  21. package/lib/orm-helpers/ormHelpers.js +12 -13
  22. package/lib/orm-helpers/ormHelpers.js.map +1 -0
  23. package/{dist → lib}/structured-file-parser/errors.js +1 -0
  24. package/lib/structured-file-parser/errors.js.map +1 -0
  25. package/{dist/file-parser → lib/structured-file-parser}/parse-row.js +2 -1
  26. package/lib/structured-file-parser/parse-row.js.map +1 -0
  27. package/{dist → lib}/structured-file-parser/sanitize-rows.js +3 -4
  28. package/lib/structured-file-parser/sanitize-rows.js.map +1 -0
  29. package/{dist → lib}/structured-file-parser/structured-file-parser.d.ts +2 -2
  30. package/lib/structured-file-parser/structured-file-parser.js +95 -0
  31. package/lib/structured-file-parser/structured-file-parser.js.map +1 -0
  32. package/{dist → lib}/types/types.d.ts +0 -6
  33. package/lib/types/types.js +191 -203
  34. package/lib/types/types.js.map +1 -0
  35. package/{dist → lib}/validations/validations.d.ts +133 -82
  36. package/lib/validations/validations.js +673 -458
  37. package/lib/validations/validations.js.map +1 -0
  38. package/package.json +7 -61
  39. package/.circleci/config.yml +0 -87
  40. package/.claude/settings.local.json +0 -7
  41. package/.eslintrc +0 -45
  42. package/.huskyrc +0 -5
  43. package/.mocharc.json +0 -3
  44. package/.nvmrc +0 -1
  45. package/.nycrc.json +0 -11
  46. package/.releaserc.json +0 -18
  47. package/.snyk +0 -12
  48. package/codecov.yml +0 -29
  49. package/commitlint.config.js +0 -1
  50. package/dist/errors/errors.js +0 -42
  51. package/dist/errors/errors.spec.d.ts +0 -1
  52. package/dist/errors/errors.spec.js +0 -23
  53. package/dist/file-parser/__tests/file-parser.spec.d.ts +0 -1
  54. package/dist/file-parser/__tests/file-parser.spec.js +0 -109
  55. package/dist/file-parser/__tests/parse-row.spec.d.ts +0 -1
  56. package/dist/file-parser/__tests/parse-row.spec.js +0 -29
  57. package/dist/file-parser/__tests/sanitize-rows.spec.d.ts +0 -1
  58. package/dist/file-parser/__tests/sanitize-rows.spec.js +0 -78
  59. package/dist/file-parser/file-parser.js +0 -55
  60. package/dist/file-parser/sanitzeRows.js +0 -18
  61. package/dist/formatting/formatting.js +0 -17
  62. package/dist/formatting/formatting.spec.d.ts +0 -1
  63. package/dist/formatting/formatting.spec.js +0 -37
  64. package/dist/index.js +0 -22
  65. package/dist/middleware/middleware.js +0 -22
  66. package/dist/orm-helpers/ormHelpers.js +0 -17
  67. package/dist/orm-helpers/ormHelpers.spec.d.ts +0 -1
  68. package/dist/orm-helpers/ormHelpers.spec.js +0 -38
  69. package/dist/structured-file-parser/structured-file-parser.js +0 -98
  70. package/dist/types/types.js +0 -203
  71. package/dist/validations/validations.js +0 -470
  72. package/dist/validations/validations.spec.d.ts +0 -1
  73. package/dist/validations/validations.spec.js +0 -463
  74. package/lib/errors/errors.spec.js +0 -37
  75. package/lib/file-parser/__tests/file-parser.spec.js +0 -107
  76. package/lib/file-parser/__tests/parse-row.spec.js +0 -35
  77. package/lib/file-parser/__tests/sanitize-rows.spec.js +0 -88
  78. package/lib/file-parser/errors.ts +0 -7
  79. package/lib/file-parser/file-parser.ts +0 -84
  80. package/lib/file-parser/parse-row.ts +0 -52
  81. package/lib/file-parser/sanitzeRows.ts +0 -32
  82. package/lib/formatting/formatting.spec.js +0 -45
  83. package/lib/index.ts +0 -19
  84. package/lib/orm-helpers/ormHelpers.spec.js +0 -41
  85. package/lib/structured-file-parser/errors.ts +0 -25
  86. package/lib/structured-file-parser/parse-row.ts +0 -52
  87. package/lib/structured-file-parser/sanitize-rows.ts +0 -24
  88. package/lib/structured-file-parser/structured-file-parser.ts +0 -155
  89. package/lib/validations/validations.spec.js +0 -603
  90. package/tsconfig.json +0 -26
  91. /package/{dist → lib}/errors/errors.d.ts +0 -0
  92. /package/{dist → lib}/file-parser/errors.d.ts +0 -0
  93. /package/{dist → lib}/file-parser/parse-row.d.ts +0 -0
  94. /package/{dist → lib}/formatting/formatting.d.ts +0 -0
  95. /package/{dist → lib}/middleware/middleware.d.ts +0 -0
  96. /package/{dist → lib}/orm-helpers/ormHelpers.d.ts +0 -0
  97. /package/{dist → lib}/structured-file-parser/errors.d.ts +0 -0
  98. /package/{dist → lib}/structured-file-parser/parse-row.d.ts +0 -0
  99. /package/{dist → lib}/structured-file-parser/sanitize-rows.d.ts +0 -0
@@ -1,17 +1,11 @@
1
1
  declare const withNullable: {};
2
2
  export function parseType(str: any): any;
3
- export function parseType(str: any): any;
4
- export function parsedTypeCheck(type: any, obj: any): any;
5
3
  export function parsedTypeCheck(type: any, obj: any): any;
6
4
  export function typeCheck(type: any, obj: any): any;
7
- export function typeCheck(type: any, obj: any): any;
8
5
  export namespace opts {
9
6
  export { withNullable as customTypes };
10
7
  }
11
8
  export function ensureType(type: any, obj: any, msg: any): boolean;
12
- export function ensureType(type: any, obj: any, msg: any): boolean;
13
- export function checkArg(obj: any, prop: any, type: any, msg: any): any;
14
9
  export function checkArg(obj: any, prop: any, type: any, msg: any): any;
15
10
  export function checkArgs(input: any, types: any): void;
16
- export function checkArgs(input: any, types: any): void;
17
11
  export {};
@@ -1,213 +1,201 @@
1
1
  const TC = require('type-check');
2
-
3
2
  const _ = require('lodash');
4
-
5
3
  const E = require('../errors/errors');
6
-
7
4
  const V = require('../validations/validations');
8
-
9
5
  const customTypes = {
10
- Integer: {
11
- typeOf: 'Number',
12
- validate(x) {
13
- return x % 1 === 0;
14
- },
15
- },
16
- IntString: {
17
- typeOf: 'String',
18
- validate: V.isInt,
19
- },
20
- BoolString: {
21
- typeOf: 'String',
22
- validate: V.isBoolean,
23
- },
24
- Hex32: {
25
- typeOf: 'String',
26
- validate(x) {
27
- return V.isHexadecimal(x) && x.length === 32;
28
- },
29
- },
30
- Email: {
31
- typeOf: 'String',
32
- validate: V.isEmail,
33
- },
34
- UUID: {
35
- typeOf: 'String',
36
- validate: V.isUUID,
37
- },
38
- UUIDv4: {
39
- typeOf: 'String',
40
- validate(x) {
41
- return V.isUUID(x, 4);
42
- },
43
- },
44
- JSON: {
45
- typeOf: 'String',
46
- validate: V.isJSON,
47
- },
48
- Url: {
49
- typeOf: 'String',
50
- validate: V.isURL,
51
- },
52
- DateString: {
53
- typeOf: 'String',
54
- validate: V.isDate,
55
- },
56
- NonEmptyArray: {
57
- typeOf: 'Array',
58
- validate: V.nonEmpty,
59
- },
60
- NonNullString: {
61
- typeOf: 'String',
62
- validate: V.nonEmpty,
63
- },
64
- CustomerReference: {
65
- typeOf: 'String',
66
- validate: V.isCustomerReference,
67
- },
68
- CustomerLabelName: {
69
- typeOf: 'String',
70
- validate: V.isCustomerLabelName,
71
- },
72
- BitcoinAddress: {
73
- typeOf: 'String',
74
- validate: V.bitcoin.isAddress,
75
- },
76
- EthereumAddress: {
77
- typeOf: 'String',
78
- validate: V.ethereum.isAddress,
79
- },
80
- EthereumTx: {
81
- typeOf: 'String',
82
- validate: V.ethereum.isTxHash,
83
- },
84
- EthereumBlockHash: {
85
- typeOf: 'String',
86
- validate: V.ethereum.isBlockHash,
87
- },
88
- EthereumWeiAmount: {
89
- typeOf: 'String',
90
- validate: V.ethereum.isValidWeiAmount,
91
- },
92
- EthereumAddressCode: {
93
- typeOf: 'String',
94
- validate: V.ethereum.isAddressCode,
95
- },
96
- MineId: {
97
- typeOf: 'String',
98
- validate(x) {
99
- return x === 'mine';
100
- },
101
- },
102
- BitcoinTxHash: {
103
- typeOf: 'String',
104
- validate: V.bitcoin.isTxHash,
105
- },
106
- BitcoinAddressArray: {
107
- typeOf: 'Array',
108
- validate(as) {
109
- return _.every(as, V.bitcoin.isAddress);
110
- },
111
- },
112
- BitcoinTxHashArray: {
113
- typeOf: 'Array',
114
- validate(as) {
115
- return _.every(as, V.bitcoin.isTxHash);
116
- },
117
- },
118
- BitcoinTxHex: {
119
- typeOf: 'String',
120
- validate: V.bitcoin.isTxHex,
121
- },
122
- BitcoinScriptHex: {
123
- typeOf: 'String',
124
- validate: V.bitcoin.isScriptHex,
125
- },
126
- BitcoinHDPath: {
127
- typeOf: 'String',
128
- validate: V.bitcoin.isHDPath,
129
- },
130
- BitcoinPublicKey: {
131
- typeOf: 'String',
132
- validate: V.bitcoin.isPublicKey,
133
- },
134
- BitcoinXpub: {
135
- typeOf: 'String',
136
- validate: V.bitcoin.isHDPublicKey,
137
- },
138
- BitcoinTxSignature: {
139
- typeOf: 'String',
140
- validate: V.bitcoin.isTxSignature,
141
- },
142
- BitcoinBlockHeight: {
143
- typeOf: 'Number',
144
- validate: V.bitcoin.isBlockHeight,
145
- },
6
+ Integer: {
7
+ typeOf: 'Number',
8
+ validate(x) {
9
+ return x % 1 === 0;
10
+ },
11
+ },
12
+ IntString: {
13
+ typeOf: 'String',
14
+ validate: V.isInt,
15
+ },
16
+ BoolString: {
17
+ typeOf: 'String',
18
+ validate: V.isBoolean,
19
+ },
20
+ Hex32: {
21
+ typeOf: 'String',
22
+ validate(x) {
23
+ return V.isHexadecimal(x) && x.length === 32;
24
+ },
25
+ },
26
+ Email: {
27
+ typeOf: 'String',
28
+ validate: V.isEmail,
29
+ },
30
+ UUID: {
31
+ typeOf: 'String',
32
+ validate: V.isUUID,
33
+ },
34
+ UUIDv4: {
35
+ typeOf: 'String',
36
+ validate(x) {
37
+ return V.isUUID(x, 4);
38
+ },
39
+ },
40
+ JSON: {
41
+ typeOf: 'String',
42
+ validate: V.isJSON,
43
+ },
44
+ Url: {
45
+ typeOf: 'String',
46
+ validate: V.isURL,
47
+ },
48
+ DateString: {
49
+ typeOf: 'String',
50
+ validate: V.isDate,
51
+ },
52
+ NonEmptyArray: {
53
+ typeOf: 'Array',
54
+ validate: V.nonEmpty,
55
+ },
56
+ NonNullString: {
57
+ typeOf: 'String',
58
+ validate: V.nonEmpty,
59
+ },
60
+ CustomerReference: {
61
+ typeOf: 'String',
62
+ validate: V.isCustomerReference,
63
+ },
64
+ CustomerLabelName: {
65
+ typeOf: 'String',
66
+ validate: V.isCustomerLabelName,
67
+ },
68
+ BitcoinAddress: {
69
+ typeOf: 'String',
70
+ validate: V.bitcoin.isAddress,
71
+ },
72
+ EthereumAddress: {
73
+ typeOf: 'String',
74
+ validate: V.ethereum.isAddress,
75
+ },
76
+ EthereumTx: {
77
+ typeOf: 'String',
78
+ validate: V.ethereum.isTxHash,
79
+ },
80
+ EthereumBlockHash: {
81
+ typeOf: 'String',
82
+ validate: V.ethereum.isBlockHash,
83
+ },
84
+ EthereumWeiAmount: {
85
+ typeOf: 'String',
86
+ validate: V.ethereum.isValidWeiAmount,
87
+ },
88
+ EthereumAddressCode: {
89
+ typeOf: 'String',
90
+ validate: V.ethereum.isAddressCode,
91
+ },
92
+ MineId: {
93
+ typeOf: 'String',
94
+ validate(x) {
95
+ return x === 'mine';
96
+ },
97
+ },
98
+ BitcoinTxHash: {
99
+ typeOf: 'String',
100
+ validate: V.bitcoin.isTxHash,
101
+ },
102
+ BitcoinAddressArray: {
103
+ typeOf: 'Array',
104
+ validate(as) {
105
+ return _.every(as, V.bitcoin.isAddress);
106
+ },
107
+ },
108
+ BitcoinTxHashArray: {
109
+ typeOf: 'Array',
110
+ validate(as) {
111
+ return _.every(as, V.bitcoin.isTxHash);
112
+ },
113
+ },
114
+ BitcoinTxHex: {
115
+ typeOf: 'String',
116
+ validate: V.bitcoin.isTxHex,
117
+ },
118
+ BitcoinScriptHex: {
119
+ typeOf: 'String',
120
+ validate: V.bitcoin.isScriptHex,
121
+ },
122
+ BitcoinHDPath: {
123
+ typeOf: 'String',
124
+ validate: V.bitcoin.isHDPath,
125
+ },
126
+ BitcoinPublicKey: {
127
+ typeOf: 'String',
128
+ validate: V.bitcoin.isPublicKey,
129
+ },
130
+ BitcoinXpub: {
131
+ typeOf: 'String',
132
+ validate: V.bitcoin.isHDPublicKey,
133
+ },
134
+ BitcoinTxSignature: {
135
+ typeOf: 'String',
136
+ validate: V.bitcoin.isTxSignature,
137
+ },
138
+ BitcoinBlockHeight: {
139
+ typeOf: 'Number',
140
+ validate: V.bitcoin.isBlockHeight,
141
+ },
146
142
  };
147
-
148
143
  // add support for nullable properties
149
- const withNullable = Object.keys(customTypes).reduce((acc, _type) => {
150
- acc[_type] = customTypes[_type];
151
- const { typeOf, validate } = customTypes[_type];
152
-
153
- // for every type, add Nullable+type. A nullable string can also be empty
154
- acc[`Nullable${_type}`] = Object.assign({}, customTypes[_type], {
155
- validate: (x) => x == null || (typeOf === 'String' && x === '') || validate(x),
156
- });
157
-
158
- return acc;
144
+ const withNullable = Object.keys(customTypes).reduce((acc, type) => {
145
+ acc[type] = customTypes[type];
146
+ const { typeOf, validate } = customTypes[type];
147
+ // for every type, add Nullable+type. A nullable string can also be empty
148
+ acc[`Nullable${type}`] = Object.assign(Object.assign({}, customTypes[type]), { validate: (x) => x == null || (typeOf === 'String' && x === '') || validate(x) });
149
+ return acc;
159
150
  }, {});
160
-
161
151
  module.exports = {
162
- parseType(str) {
163
- return TC.parseType(str);
164
- },
165
- parsedTypeCheck(type, obj) {
166
- return TC.parsedTypeCheck(type, obj, this.opts);
167
- },
168
- typeCheck(type, obj) {
169
- return TC.typeCheck(type, obj, this.opts);
170
- },
171
- opts: {
172
- customTypes: withNullable,
173
- },
174
- ensureType(type, obj, msg) {
175
- return V.ensure(this.typeCheck(type, obj), msg);
176
- },
177
- checkArg(obj, prop, type, msg) {
178
- let message;
179
- if (msg == null) {
180
- message = `Invalid ${prop}`;
181
- } else {
182
- message = msg;
183
- }
184
- this.ensureType(type, obj[prop], message);
185
- return obj[prop];
186
- },
187
- checkArgs(input, types) {
188
- const inputKeys = {};
189
- const [typ] = types;
190
- const fields = typ.of;
191
- let numInputKeys = 0;
192
- let numKeys;
193
-
194
- Object.keys(input).forEach((k) => {
195
- inputKeys[k] = true;
196
- numInputKeys += 1;
197
- });
198
-
199
- numKeys = 0;
200
-
201
- Object.keys(fields).forEach((key) => {
202
- const objTypes = fields[key];
203
- V.ensure(this.parsedTypeCheck(objTypes, input[key]), `Invalid ${key}`);
204
- if (inputKeys[key]) {
205
- numKeys += 1;
206
- }
207
- });
208
-
209
- if (!(typ.subset || numInputKeys === numKeys)) {
210
- throw new E.BadRequest('invalid extra arguments are present');
211
- }
212
- },
152
+ parseType(str) {
153
+ return TC.parseType(str);
154
+ },
155
+ parsedTypeCheck(type, obj) {
156
+ return TC.parsedTypeCheck(type, obj, this.opts);
157
+ },
158
+ typeCheck(type, obj) {
159
+ return TC.typeCheck(type, obj, this.opts);
160
+ },
161
+ opts: {
162
+ customTypes: withNullable,
163
+ },
164
+ ensureType(type, obj, msg) {
165
+ return V.ensure(this.typeCheck(type, obj), msg);
166
+ },
167
+ checkArg(obj, prop, type, msg) {
168
+ let message;
169
+ if (msg == null) {
170
+ message = `Invalid ${prop}`;
171
+ }
172
+ else {
173
+ message = msg;
174
+ }
175
+ this.ensureType(type, obj[prop], message);
176
+ return obj[prop];
177
+ },
178
+ checkArgs(input, types) {
179
+ const inputKeys = {};
180
+ const [typ] = types;
181
+ const fields = typ.of;
182
+ let numInputKeys = 0;
183
+ let numKeys;
184
+ Object.keys(input).forEach((k) => {
185
+ inputKeys[k] = true;
186
+ numInputKeys += 1;
187
+ });
188
+ numKeys = 0;
189
+ Object.keys(fields).forEach((key) => {
190
+ const objTypes = fields[key];
191
+ V.ensure(this.parsedTypeCheck(objTypes, input[key]), `Invalid ${key}`);
192
+ if (inputKeys[key]) {
193
+ numKeys += 1;
194
+ }
195
+ });
196
+ if (!(typ.subset || numInputKeys === numKeys)) {
197
+ throw new E.BadRequest('invalid extra arguments are present');
198
+ }
199
+ },
213
200
  };
201
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../libs/aml-utils/lib/types/types.js"],"names":[],"mappings":"AAAA,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEjC,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE5B,MAAM,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAEtC,MAAM,CAAC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAEhD,MAAM,WAAW,GAAG;IAClB,OAAO,EAAE;QACP,MAAM,EAAE,QAAQ;QAChB,QAAQ,CAAC,CAAC;YACR,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;KACF;IACD,SAAS,EAAE;QACT,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,CAAC,CAAC,KAAK;KAClB;IACD,UAAU,EAAE;QACV,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,CAAC,CAAC,SAAS;KACtB;IACD,KAAK,EAAE;QACL,MAAM,EAAE,QAAQ;QAChB,QAAQ,CAAC,CAAC;YACR,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC;QAC/C,CAAC;KACF;IACD,KAAK,EAAE;QACL,MAAM,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C,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,EAAE,CAAC,CAAC;YACvE,IAAI,SAAS,CAAC,GAAG,CAAC,EAAE;gBAClB,OAAO,IAAI,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,IAAI,YAAY,KAAK,OAAO,CAAC,EAAE;YAC7C,MAAM,IAAI,CAAC,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC;SAC/D;IACH,CAAC;CACF,CAAC","sourcesContent":["const TC = require('type-check');\n\nconst _ = require('lodash');\n\nconst E = require('../errors/errors');\n\nconst V = require('../validations/validations');\n\nconst customTypes = {\n Integer: {\n typeOf: 'Number',\n validate(x) {\n return x % 1 === 0;\n },\n },\n IntString: {\n typeOf: 'String',\n validate: V.isInt,\n },\n BoolString: {\n typeOf: 'String',\n validate: V.isBoolean,\n },\n Hex32: {\n typeOf: 'String',\n validate(x) {\n return V.isHexadecimal(x) && x.length === 32;\n },\n },\n Email: {\n typeOf: 'String',\n validate: V.isEmail,\n },\n UUID: {\n typeOf: 'String',\n validate: V.isUUID,\n },\n UUIDv4: {\n typeOf: 'String',\n validate(x) {\n return V.isUUID(x, 4);\n },\n },\n JSON: {\n typeOf: 'String',\n validate: V.isJSON,\n },\n Url: {\n typeOf: 'String',\n validate: V.isURL,\n },\n DateString: {\n typeOf: 'String',\n validate: V.isDate,\n },\n NonEmptyArray: {\n typeOf: 'Array',\n validate: V.nonEmpty,\n },\n NonNullString: {\n typeOf: 'String',\n validate: V.nonEmpty,\n },\n CustomerReference: {\n typeOf: 'String',\n validate: V.isCustomerReference,\n },\n CustomerLabelName: {\n typeOf: 'String',\n validate: V.isCustomerLabelName,\n },\n BitcoinAddress: {\n typeOf: 'String',\n validate: V.bitcoin.isAddress,\n },\n EthereumAddress: {\n typeOf: 'String',\n validate: V.ethereum.isAddress,\n },\n EthereumTx: {\n typeOf: 'String',\n validate: V.ethereum.isTxHash,\n },\n EthereumBlockHash: {\n typeOf: 'String',\n validate: V.ethereum.isBlockHash,\n },\n EthereumWeiAmount: {\n typeOf: 'String',\n validate: V.ethereum.isValidWeiAmount,\n },\n EthereumAddressCode: {\n typeOf: 'String',\n validate: V.ethereum.isAddressCode,\n },\n MineId: {\n typeOf: 'String',\n validate(x) {\n return x === 'mine';\n },\n },\n BitcoinTxHash: {\n typeOf: 'String',\n validate: V.bitcoin.isTxHash,\n },\n BitcoinAddressArray: {\n typeOf: 'Array',\n validate(as) {\n return _.every(as, V.bitcoin.isAddress);\n },\n },\n BitcoinTxHashArray: {\n typeOf: 'Array',\n validate(as) {\n return _.every(as, V.bitcoin.isTxHash);\n },\n },\n BitcoinTxHex: {\n typeOf: 'String',\n validate: V.bitcoin.isTxHex,\n },\n BitcoinScriptHex: {\n typeOf: 'String',\n validate: V.bitcoin.isScriptHex,\n },\n BitcoinHDPath: {\n typeOf: 'String',\n validate: V.bitcoin.isHDPath,\n },\n BitcoinPublicKey: {\n typeOf: 'String',\n validate: V.bitcoin.isPublicKey,\n },\n BitcoinXpub: {\n typeOf: 'String',\n validate: V.bitcoin.isHDPublicKey,\n },\n BitcoinTxSignature: {\n typeOf: 'String',\n validate: V.bitcoin.isTxSignature,\n },\n BitcoinBlockHeight: {\n typeOf: 'Number',\n validate: V.bitcoin.isBlockHeight,\n },\n};\n\n// add support for nullable properties\nconst withNullable = Object.keys(customTypes).reduce((acc, type) => {\n acc[type] = customTypes[type];\n const { typeOf, validate } = customTypes[type];\n\n // for every type, add Nullable+type. A nullable string can also be empty\n acc[`Nullable${type}`] = { ...customTypes[type], validate: (x) => x == null || (typeOf === 'String' && x === '') || validate(x) };\n\n return acc;\n}, {});\n\nmodule.exports = {\n parseType(str) {\n return TC.parseType(str);\n },\n parsedTypeCheck(type, obj) {\n return TC.parsedTypeCheck(type, obj, this.opts);\n },\n typeCheck(type, obj) {\n return TC.typeCheck(type, obj, this.opts);\n },\n opts: {\n customTypes: withNullable,\n },\n ensureType(type, obj, msg) {\n return V.ensure(this.typeCheck(type, obj), msg);\n },\n checkArg(obj, prop, type, msg) {\n let message;\n if (msg == null) {\n message = `Invalid ${prop}`;\n } else {\n message = msg;\n }\n this.ensureType(type, obj[prop], message);\n return obj[prop];\n },\n checkArgs(input, types) {\n const inputKeys = {};\n const [typ] = types;\n const fields = typ.of;\n let numInputKeys = 0;\n let numKeys;\n\n Object.keys(input).forEach((k) => {\n inputKeys[k] = true;\n numInputKeys += 1;\n });\n\n numKeys = 0;\n\n Object.keys(fields).forEach((key) => {\n const objTypes = fields[key];\n V.ensure(this.parsedTypeCheck(objTypes, input[key]), `Invalid ${key}`);\n if (inputKeys[key]) {\n numKeys += 1;\n }\n });\n\n if (!(typ.subset || numInputKeys === numKeys)) {\n throw new E.BadRequest('invalid extra arguments are present');\n }\n },\n};\n"]}