@dashevo/dapi-client 0.23.0-dev.9 → 0.24.0-dev.2

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/README.md CHANGED
@@ -101,7 +101,7 @@ client.core.getBestBlockHash(options).then((r) => {
101
101
 
102
102
  ## Documentation
103
103
 
104
- More extensive documentation available at https://dashevo.github.io/platform/DAPI-Client/.
104
+ More extensive documentation available at https://dashpay.github.io/platform/DAPI-Client/.
105
105
 
106
106
 
107
107
  ## Contributing
@@ -10,13 +10,15 @@ class DAPIAddress {
10
10
  }
11
11
 
12
12
  if (typeof address === 'string') {
13
- const [host, httpPort, grpcPort] = address.split(':');
13
+ const [host, httpPort, grpcPort, ssl] = address.split(':');
14
14
 
15
15
  // eslint-disable-next-line no-param-reassign
16
16
  address = {
17
17
  host,
18
18
  httpPort: httpPort ? parseInt(httpPort, 10) : DAPIAddress.DEFAULT_HTTP_PORT,
19
19
  grpcPort: grpcPort ? parseInt(grpcPort, 10) : DAPIAddress.DEFAULT_GRPC_PORT,
20
+ protocol: ssl === 'no-ssl' ? 'http' : DAPIAddress.DEFAULT_PROTOCOL,
21
+ allowSelfSignedCertificate: ssl === 'self-signed',
20
22
  };
21
23
  }
22
24
 
@@ -24,15 +26,26 @@ class DAPIAddress {
24
26
  throw new DAPIAddressHostMissingError();
25
27
  }
26
28
 
29
+ this.protocol = address.protocol || DAPIAddress.DEFAULT_PROTOCOL;
27
30
  this.host = address.host;
28
31
  this.httpPort = address.httpPort || DAPIAddress.DEFAULT_HTTP_PORT;
29
32
  this.grpcPort = address.grpcPort || DAPIAddress.DEFAULT_GRPC_PORT;
30
33
  this.proRegTxHash = address.proRegTxHash;
34
+ this.allowSelfSignedCertificate = address.allowSelfSignedCertificate || false;
31
35
 
32
36
  this.banCount = 0;
33
37
  this.banStartTime = undefined;
34
38
  }
35
39
 
40
+ /**
41
+ * Get protocol
42
+ *
43
+ * @returns {string}
44
+ */
45
+ getProtocol() {
46
+ return this.protocol;
47
+ }
48
+
36
49
  /**
37
50
  * Get host
38
51
  *
@@ -150,6 +163,13 @@ class DAPIAddress {
150
163
  return this.banCount > 0;
151
164
  }
152
165
 
166
+ /**
167
+ * @returns {boolean}
168
+ */
169
+ isSelfSignedCertificateAllowed() {
170
+ return this.allowSelfSignedCertificate;
171
+ }
172
+
153
173
  /**
154
174
  * Return DAPIAddress as plain object
155
175
  *
@@ -157,27 +177,32 @@ class DAPIAddress {
157
177
  */
158
178
  toJSON() {
159
179
  return {
180
+ protocol: this.getProtocol(),
160
181
  host: this.getHost(),
161
182
  httpPort: this.getHttpPort(),
162
183
  grpcPort: this.getGrpcPort(),
163
184
  proRegTxHash: this.getProRegTxHash(),
185
+ allowSelfSignedCertificate: this.isSelfSignedCertificateAllowed(),
164
186
  };
165
187
  }
166
188
 
167
189
  toString() {
168
- return `${this.getHost()}:${this.getHttpPort()}:${this.getGrpcPort()}`;
190
+ return `${this.getProtocol()}://${this.getHost()}:${this.getHttpPort()}:${this.getGrpcPort()}`;
169
191
  }
170
192
  }
171
193
 
172
194
  DAPIAddress.DEFAULT_HTTP_PORT = 3000;
173
195
  DAPIAddress.DEFAULT_GRPC_PORT = 3010;
196
+ DAPIAddress.DEFAULT_PROTOCOL = 'http';
174
197
 
175
198
  /**
176
199
  * @typedef {object} RawDAPIAddress
200
+ * @property {string} protocol
177
201
  * @property {string} host
178
202
  * @property {number} [httpPort=3000]
179
203
  * @property {number} [grpcPort=3010]
180
204
  * @property {string} [proRegTxHash]
205
+ * @property {bool} [selfSigned]
181
206
  */
182
207
 
183
208
  module.exports = DAPIAddress;
@@ -36,7 +36,9 @@ class ListDAPIAddressProvider {
36
36
  if (network && network.regtestEnabled) {
37
37
  const randomNodeIndex = Math.floor(Math.random() * liveAddresses.length);
38
38
 
39
+ liveAddress.protocol = 'https';
39
40
  liveAddress.host = '127.0.0.1';
41
+ liveAddress.allowSelfSignedCertificate = true;
40
42
  liveAddress.httpPort = 3000 + randomNodeIndex * 100;
41
43
  liveAddress.grpcPort = 3010 + randomNodeIndex * 100;
42
44
  }
@@ -12,156 +12,120 @@ module.exports = {
12
12
  // that breaks test suite and application logic. Temporary solution is to hardcode
13
13
  // reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
14
14
  dapiAddressesWhiteList: [
15
- '52.11.85.154',
16
- '52.38.248.133',
17
- '34.212.231.240',
18
- '54.185.249.226',
19
- '34.215.57.86',
20
- '54.190.73.116',
21
- '34.214.2.219',
22
- '54.212.84.164',
23
- '35.164.96.124',
24
- '34.219.81.129',
25
- '34.221.42.205',
26
- '34.208.88.128',
27
- '54.189.162.193',
28
- '34.220.124.90',
29
- '54.201.242.241',
30
- '54.68.10.46',
31
- '34.210.81.39',
32
- '18.237.47.243',
33
- '54.187.229.6',
34
- '34.214.102.160',
35
- '34.219.93.145',
36
- '35.165.37.186',
37
- '54.202.157.120',
38
- '34.215.144.176',
39
- '52.13.119.69',
40
- '34.220.12.188',
41
- '18.237.5.33',
42
- '54.191.32.70',
43
- '54.213.219.155',
44
- '35.167.25.157',
45
- '54.213.89.75',
46
- '52.32.232.156',
47
- '34.212.226.44',
48
- '35.160.140.37',
49
- '52.11.133.244',
50
- '54.201.189.185',
51
- '34.216.200.22',
52
- '34.220.144.226',
53
- '34.216.195.19',
54
- '54.185.1.69',
55
- '35.166.29.155',
56
- '18.237.147.160',
57
- '34.220.228.214',
58
- '54.212.75.8',
59
- '35.163.152.74',
60
- '18.236.78.191',
61
- '54.148.106.179',
62
- '34.211.46.222',
63
- '35.160.13.25',
64
- '34.220.17.107',
65
- '34.212.65.137',
66
- '54.185.249.172',
67
- '54.70.65.199',
68
- '54.69.210.42',
69
- '18.236.160.247',
70
- '54.245.197.173',
71
- '54.187.11.213',
72
- '54.218.70.46',
73
- '35.165.207.13',
74
- '34.211.49.3',
75
- '34.219.36.94',
76
- '34.222.127.158',
77
- '34.222.242.228',
78
- '52.26.220.40',
79
- '52.36.244.225',
80
- '34.222.225.76',
81
- '18.236.169.114',
82
- '54.201.236.212',
83
- '54.203.241.214',
84
- '34.221.254.29',
85
- '54.187.50.120',
86
- '54.184.140.221',
87
- '34.215.192.133',
88
- '35.164.180.39',
89
- '54.184.183.20',
90
- '52.43.197.215',
91
- '54.201.42.245',
92
- '54.218.113.88',
93
- '54.244.141.192',
94
- '34.217.98.54',
95
- '34.222.168.33',
96
- '52.32.143.49',
97
- '54.187.224.80',
98
- '54.189.87.145',
99
- '52.39.164.105',
100
- '54.70.55.164',
101
- '54.214.68.206',
102
- '54.201.239.109',
103
- '34.215.146.162',
104
- '18.236.233.120',
105
- '54.190.217.178',
106
- '34.220.41.134',
107
- '34.212.178.215',
108
- '34.219.169.55',
109
- '54.218.251.43',
110
- '18.236.216.191',
111
- '54.188.17.60',
112
- '54.191.227.118',
113
- '34.213.5.102',
114
- '35.166.79.235',
115
- '54.71.107.225',
116
- '54.201.162.86',
117
- '52.34.141.75',
118
- '34.217.43.189',
119
- '52.38.77.105',
120
- '52.11.252.174',
121
- '54.191.221.246',
122
- '54.218.107.83',
123
- '54.212.18.218',
124
- '34.220.53.77',
125
- '54.244.41.15',
126
- '34.222.135.203',
127
- '54.191.110.152',
128
- '34.208.190.130',
129
- '34.222.6.55',
130
- '54.184.7.184',
131
- '52.12.47.86',
132
- '34.217.28.248',
133
- '54.149.252.146',
134
- '54.149.80.193',
135
- '34.215.55.0',
136
- '34.220.74.48',
137
- '34.209.124.112',
138
- '34.217.23.70',
139
- '34.222.102.137',
140
- '34.209.166.42',
141
- '18.236.128.49',
142
- '35.163.99.20',
143
- '34.215.67.224',
144
- '34.211.244.117',
145
- '18.236.199.232',
146
- '54.191.237.52',
147
- '34.223.226.224',
148
- '54.149.133.143',
149
- '52.41.198.242',
150
- '54.148.215.161',
151
- '54.188.193.70',
152
- '54.218.104.194',
153
- '34.209.73.208',
154
- '34.220.88.70',
155
- '52.40.101.104',
156
- '18.236.68.153',
157
- '34.218.76.179',
158
- '34.219.94.178',
159
- '54.218.127.128',
160
- '52.27.198.246',
161
- '18.237.204.153',
162
- '35.166.57.113',
163
- '54.191.15.3',
164
- '18.237.128.46',
15
+ '34.216.69.175',
16
+ '34.218.75.96',
17
+ '18.237.220.27',
18
+ '54.191.38.234',
19
+ '35.93.95.157',
20
+ '35.166.240.246',
21
+ '35.91.186.151',
22
+ '35.161.123.225',
23
+ '54.212.169.115',
24
+ '54.187.168.12',
25
+ '18.236.191.199',
26
+ '18.237.165.224',
27
+ '52.36.42.1',
28
+ '34.220.32.216',
29
+ '34.222.238.250',
30
+ '35.93.34.215',
31
+ '34.221.10.165',
32
+ '54.203.241.195',
33
+ '35.92.138.231',
34
+ '52.38.169.156',
35
+ '54.187.21.108',
36
+ '34.219.48.219',
37
+ '34.217.38.221',
38
+ '35.92.157.107',
39
+ '18.236.82.230',
40
+ '54.184.225.22',
41
+ '18.237.144.120',
42
+ '18.237.254.214',
43
+ '35.88.29.196',
44
+ '35.89.126.245',
45
+ '34.217.148.69',
46
+ '35.89.193.46',
47
+ '35.89.119.37',
48
+ '54.186.161.236',
49
+ '52.13.63.7',
50
+ '18.236.233.225',
51
+ '54.191.138.72',
52
+ '54.191.59.75',
53
+ '18.237.160.84',
54
+ '54.218.236.193',
55
+ '54.148.178.140',
56
+ '35.161.168.136',
57
+ '35.161.33.22',
58
+ '35.160.130.44',
59
+ '34.212.104.247',
60
+ '52.13.29.83',
61
+ '54.149.39.172',
62
+ '35.89.93.255',
63
+ '35.85.46.137',
64
+ '54.188.154.252',
65
+ '54.218.11.172',
66
+ '54.186.47.235',
67
+ '54.244.145.48',
68
+ '18.236.232.153',
69
+ '34.220.226.135',
70
+ '34.220.30.59',
71
+ '18.237.160.97',
72
+ '18.236.146.99',
73
+ '35.88.169.18',
74
+ '35.164.17.198',
75
+ '54.218.80.158',
76
+ '34.220.102.107',
77
+ '35.165.60.113',
78
+ '34.215.234.63',
79
+ '35.89.146.226',
80
+ '35.89.86.26',
81
+ '35.88.160.231',
82
+ '54.245.8.155',
83
+ '52.36.221.94',
84
+ '52.35.46.188',
85
+ '34.221.153.67',
86
+ '54.212.153.15',
87
+ '35.85.55.192',
88
+ '35.89.105.90',
89
+ '52.24.22.52',
90
+ '54.212.33.96',
91
+ '52.10.19.238',
92
+ '35.160.190.165',
93
+ '34.219.3.61',
94
+ '54.187.32.187',
95
+ '35.162.221.77',
96
+ '35.91.64.183',
97
+ '18.236.189.15',
98
+ '35.91.145.195',
99
+ '54.186.251.30',
100
+ '54.245.9.46',
101
+ '35.91.48.128',
102
+ '54.244.75.85',
103
+ '34.221.159.53',
104
+ '35.89.88.166',
105
+ '54.185.249.165',
106
+ '54.245.9.209',
107
+ '34.222.167.162',
108
+ '54.191.88.232',
109
+ '54.191.111.112',
110
+ '18.237.146.37',
111
+ '35.89.148.27',
112
+ '35.91.8.48',
113
+ '18.236.208.138',
114
+ '54.213.60.60',
115
+ '35.92.151.94',
116
+ '18.237.241.37',
117
+ '54.202.209.229',
118
+ '34.221.9.70',
119
+ '35.89.38.62',
120
+ '54.218.81.193',
121
+ '34.221.158.21',
122
+ '35.88.97.57',
123
+ '54.68.247.40',
124
+ '35.88.168.176',
125
+ '35.89.202.171',
126
+ '34.220.106.205',
127
+ '34.210.86.23',
128
+ '44.230.40.184',
165
129
  ],
166
130
  },
167
131
  evonet: {
@@ -132,6 +132,7 @@ class GrpcTransport {
132
132
  * @returns {string}
133
133
  */
134
134
  makeGrpcUrlFromAddress(address) {
135
+ let protocol = address.getProtocol();
135
136
  let port = address.getHttpPort();
136
137
 
137
138
  // For NodeJS Client
@@ -139,9 +140,11 @@ class GrpcTransport {
139
140
  && process.versions != null
140
141
  && process.versions.node != null) {
141
142
  port = address.getGrpcPort();
142
- }
143
143
 
144
- const protocol = address.getHttpPort() === 443 ? 'https' : 'http';
144
+ if (address.isSelfSignedCertificateAllowed()) {
145
+ protocol = 'http';
146
+ }
147
+ }
145
148
 
146
149
  return `${protocol}://${address.getHost()}:${port}`;
147
150
  }
@@ -50,32 +50,34 @@ function createGrpcTransportError(grpcError, dapiAddress) {
50
50
 
51
51
  const message = grpcError.details || grpcError.message;
52
52
 
53
+ let metadata = {};
54
+
53
55
  if (grpcError.metadata) {
54
56
  // In cases of gRPC-Web client we get plain map instead of Metadata instance
55
- let metadataMap = grpcError.metadata;
57
+ metadata = grpcError.metadata;
56
58
  if (grpcError.metadata instanceof Metadata) {
57
- metadataMap = grpcError.metadata.getMap();
59
+ metadata = grpcError.metadata.getMap();
58
60
  }
61
+ }
59
62
 
60
- // Error data
61
- const driveErrorData = metadataMap['drive-error-data-bin'];
62
- if (driveErrorData) {
63
- const encodedData = Buffer.from(driveErrorData, 'base64');
64
- data = cbor.decode(encodedData);
65
- }
63
+ // Error data
64
+ const driveErrorData = metadata['drive-error-data-bin'];
65
+ if (driveErrorData) {
66
+ const encodedData = Buffer.from(driveErrorData, 'base64');
67
+ data = cbor.decode(encodedData);
68
+ }
66
69
 
67
- // Error code
68
- const driveErrorCode = metadataMap.code;
69
- if (driveErrorCode) {
70
- code = Number(driveErrorCode);
71
- }
70
+ // Error code
71
+ const driveErrorCode = metadata.code;
72
+ if (driveErrorCode) {
73
+ code = Number(driveErrorCode);
74
+ }
72
75
 
73
- // Error stack
74
- const driveErrorStack = metadataMap['stack-bin'];
75
- if (driveErrorStack) {
76
- const encodedStack = Buffer.from(driveErrorStack, 'base64');
77
- data.stack = cbor.decode(encodedStack);
78
- }
76
+ // Error stack
77
+ const driveErrorStack = metadata['stack-bin'];
78
+ if (driveErrorStack) {
79
+ const encodedStack = Buffer.from(driveErrorStack, 'base64');
80
+ data.stack = cbor.decode(encodedStack);
79
81
  }
80
82
 
81
83
  // Specialized classes
@@ -100,13 +102,6 @@ function createGrpcTransportError(grpcError, dapiAddress) {
100
102
  }
101
103
 
102
104
  if (code === GrpcErrorCodes.INTERNAL) {
103
- if (grpcError.metadata) {
104
- const metaStack = grpcError.metadata.get('stack-bin');
105
- if (metaStack && metaStack.length > 0) {
106
- data.stack = cbor.decode(metaStack[0]);
107
- }
108
- }
109
-
110
105
  return new InternalServerError(
111
106
  code,
112
107
  message,
@@ -65,8 +65,10 @@ class JsonRpcTransport {
65
65
 
66
66
  try {
67
67
  const result = await this.requestJsonRpc(
68
+ address.getProtocol(),
68
69
  address.getHost(),
69
70
  address.getHttpPort(),
71
+ address.isSelfSignedCertificateAllowed(),
70
72
  method,
71
73
  params,
72
74
  requestOptions,
@@ -1,20 +1,21 @@
1
1
  const axios = require('axios');
2
+ const https = require('https');
2
3
 
3
4
  const JsonRpcError = require('./errors/JsonRpcError');
4
5
  const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
5
6
 
6
7
  /**
7
8
  * @typedef {requestJsonRpc}
9
+ * @param {string} protocol
8
10
  * @param {string} host
9
11
  * @param {number} port
12
+ * @param {boolean} selfSigned
10
13
  * @param {string} method
11
14
  * @param {object} params
12
15
  * @param {object} [options]
13
16
  * @returns {Promise<*>}
14
17
  */
15
- async function requestJsonRpc(host, port, method, params, options = {}) {
16
- const protocol = port === 443 ? 'https' : 'http';
17
-
18
+ async function requestJsonRpc(protocol, host, port, selfSigned, method, params, options = {}) {
18
19
  const url = `${protocol}://${host}${port && port !== 443 ? `:${port}` : ''}`;
19
20
 
20
21
  const payload = {
@@ -30,8 +31,10 @@ async function requestJsonRpc(host, port, method, params, options = {}) {
30
31
  }
31
32
 
32
33
  const requestInfo = {
34
+ protocol,
33
35
  host,
34
36
  port,
37
+ selfSigned,
35
38
  method,
36
39
  params,
37
40
  options,
@@ -39,11 +42,23 @@ async function requestJsonRpc(host, port, method, params, options = {}) {
39
42
 
40
43
  let response;
41
44
 
45
+ const config = { timeout: options.timeout };
46
+ // For NodeJS Client
47
+ if (typeof process !== 'undefined'
48
+ && process.versions != null
49
+ && process.versions.node != null
50
+ && protocol === 'https'
51
+ && selfSigned) {
52
+ config.httpsAgent = new https.Agent({
53
+ rejectUnauthorized: false,
54
+ });
55
+ }
56
+
42
57
  try {
43
58
  response = await axios.post(
44
59
  url,
45
60
  payload,
46
- { timeout: options.timeout },
61
+ config,
47
62
  );
48
63
  } catch (error) {
49
64
  if (error.response && error.response.status >= 500) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "0.23.0-dev.9",
3
+ "version": "0.24.0-dev.2",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,13 +26,13 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "~0.23.0-dev.9",
30
- "@dashevo/dash-spv": "~1.1.7-6",
31
- "@dashevo/dashcore-lib": "~0.19.41",
32
- "@dashevo/dpp": "~0.23.0-dev.9",
33
- "@dashevo/grpc-common": "~0.23.0-dev.9",
29
+ "@dashevo/dapi-grpc": "0.24.0-dev.2",
30
+ "@dashevo/dash-spv": "0.24.0-dev.2",
31
+ "@dashevo/dashcore-lib": "~0.19.44",
32
+ "@dashevo/dpp": "0.24.0-dev.2",
33
+ "@dashevo/grpc-common": "0.24.0-dev.2",
34
34
  "@grpc/grpc-js": "^1.3.7",
35
- "axios": "^0.21.1",
35
+ "axios": "^0.27.2",
36
36
  "bs58": "^4.0.1",
37
37
  "cbor": "^8.0.0",
38
38
  "lodash.sample": "^4.2.1",
@@ -54,7 +54,7 @@
54
54
  "eslint-plugin-import": "^2.24.2",
55
55
  "eslint-plugin-jsdoc": "^27.0.0",
56
56
  "events": "^3.3.0",
57
- "karma": "^6.3.4",
57
+ "karma": "^6.4.1",
58
58
  "karma-chai": "^0.1.0",
59
59
  "karma-chrome-launcher": "^3.1.0",
60
60
  "karma-firefox-launcher": "^2.1.1",