@dashevo/dash-spv 1.1.6 → 1.1.7-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/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ dist/
2
+ .nyc_output/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-2022 Dash Core Group, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # dash-spv
2
2
 
3
- > Temporary repo until spv functions moved into dashcore-lib
4
-
5
- No new features should be added to this repo.
3
+ Set of SPV function used by js-dapi-client package
6
4
 
7
5
  ## License
8
6
 
package/config/config.js CHANGED
@@ -35,6 +35,16 @@ module.exports = {
35
35
  nonce: 3861367235,
36
36
  });
37
37
  },
38
+ getRegtestGenesis() {
39
+ return utils.normalizeHeader({
40
+ version: 1,
41
+ previousblockhash: '0000000000000000000000000000000000000000000000000000000000000000',
42
+ merkleroot: 'e0028eb9648db56b1ac77cf090b99048a8007e2bb64b68f092c03c7f56a662c7',
43
+ time: 1390666206,
44
+ bits: '1e0ffff0',
45
+ nonce: 3861367235,
46
+ });
47
+ },
38
48
  getLivenetGenesis() {
39
49
  throw Error('Livenet genesis not yet implemented');
40
50
  },
package/lib/blockstore.js CHANGED
@@ -53,5 +53,4 @@ class BlockStore {
53
53
  }
54
54
  }
55
55
 
56
-
57
56
  module.exports = BlockStore;
package/lib/consensus.js CHANGED
@@ -6,7 +6,7 @@ const MIN_TIMESTAMP_HEADERS = 11;
6
6
  const MIN_DGW_HEADERS = 24;
7
7
 
8
8
  function getMedianTimestamp(headers) {
9
- const timestamps = headers.map(h => h.time);
9
+ const timestamps = headers.map((h) => h.time);
10
10
  const median = (arr) => {
11
11
  const mid = Math.floor(arr.length / 2);
12
12
  const nums = [...arr].sort((a, b) => a - b);
@@ -22,7 +22,7 @@ function hasGreaterThanMedianTimestamp(newHeader, previousHeaders) {
22
22
  const headerNormalised = utils.normalizeHeader(newHeader);
23
23
  const normalizedLatestHeaders = previousHeaders.slice(
24
24
  Math.max(previousHeaders.length - MIN_TIMESTAMP_HEADERS, 0),
25
- ).map(h => utils.normalizeHeader(h));
25
+ ).map((h) => utils.normalizeHeader(h));
26
26
  return getMedianTimestamp(normalizedLatestHeaders) < headerNormalised.time;
27
27
  }
28
28
 
@@ -32,7 +32,7 @@ function isValidBlockHeader(newHeader, previousHeaders, network = 'mainnet') {
32
32
  && newHeader.validTimestamp()
33
33
  && hasGreaterThanMedianTimestamp(newHeader, previousHeaders)
34
34
  && hasValidTarget(
35
- utils.getDgwBlock(newHeader), previousHeaders.map(h => utils.getDgwBlock(h)), network,
35
+ utils.getDgwBlock(newHeader), previousHeaders.map((h) => utils.getDgwBlock(h)), network,
36
36
  );
37
37
  }
38
38
  return newHeader.validProofOfWork()
@@ -11,10 +11,10 @@ const merkleproofs = {
11
11
  validateTxProofs: (merkleBlock, transactions) => {
12
12
  let txToFilter = transactions.slice();
13
13
  if (typeof transactions[0] === 'string') {
14
- txToFilter = txToFilter.map(tx => DashUtil.toHash(tx).toString('hex'));
14
+ txToFilter = txToFilter.map((tx) => DashUtil.toHash(tx).toString('hex'));
15
15
  }
16
16
  return merkleBlock.validMerkleTree
17
- && txToFilter.filter(tx => merkleBlock.hasTransaction(tx)).length === transactions.length;
17
+ && txToFilter.filter((tx) => merkleBlock.hasTransaction(tx)).length === transactions.length;
18
18
  },
19
19
  };
20
20
 
package/lib/spvchain.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const BlockStore = require('./blockstore');
2
2
  const config = require('../config/config');
3
3
  const Consensus = require('./consensus');
4
- const utils = require('../lib/utils');
4
+ const utils = require('./utils');
5
5
 
6
6
  const SpvChain = class {
7
7
  constructor(chainType, confirms = 100, startBlock) {
@@ -32,6 +32,14 @@ const SpvChain = class {
32
32
  }
33
33
  this.root = config.getDevnetGenesis();
34
34
  break;
35
+ case 'regtest':
36
+ this.network = 'regtest';
37
+ if (startBlock) {
38
+ this.root = startBlock;
39
+ break;
40
+ }
41
+ this.root = config.getRegtestGenesis();
42
+ break;
35
43
  case 'livenet':
36
44
  this.network = 'mainnet';
37
45
  if (startBlock) {
@@ -122,9 +130,9 @@ const SpvChain = class {
122
130
 
123
131
  /** @private */
124
132
  isDuplicate(compareHash) {
125
- return this.getAllBranches().map(branch => branch.map(node => node.hash))
126
- .concat(this.orphanBlocks.map(orphan => orphan.hash))
127
- .filter(hash => hash === compareHash).length > 0;
133
+ return this.getAllBranches().map((branch) => branch.map((node) => node.hash))
134
+ .concat(this.orphanBlocks.map((orphan) => orphan.hash))
135
+ .filter((hash) => hash === compareHash).length > 0;
128
136
  }
129
137
 
130
138
  /** @private */
@@ -246,7 +254,7 @@ const SpvChain = class {
246
254
  return blockInDB;
247
255
  }
248
256
 
249
- return this.getLongestChain().filter(h => h.hash === hash)[0];
257
+ return this.getLongestChain().filter((h) => h.hash === hash)[0];
250
258
  });
251
259
  }
252
260
 
@@ -287,7 +295,7 @@ const SpvChain = class {
287
295
  return true;
288
296
  }
289
297
  }
290
- const normalizedHeaders = headers.map(h => utils.normalizeHeader(h));
298
+ const normalizedHeaders = headers.map((h) => utils.normalizeHeader(h));
291
299
  const isOrphan = !SpvChain.isParentChild(normalizedHeaders[0], this.getTipHeader());
292
300
 
293
301
  const allValid = normalizedHeaders.reduce(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dashevo/dash-spv",
3
- "version": "1.1.6",
4
- "description": "Temporary repo until spv functions moved into dashcore-lib",
3
+ "version": "1.1.7-2",
4
+ "description": "Repository containing SPV functions used by @dashevo",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "mocha test/ --no-timeouts --recursive",
@@ -12,16 +12,16 @@
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
14
  "@dashevo/dark-gravity-wave": "^1.1.1",
15
- "@dashevo/dashcore-lib": "^0.17.4",
16
15
  "@dashevo/dash-util": "^2.0.3",
17
- "levelup": "^4.0.1",
18
- "memdown": "^3.0.0"
16
+ "@dashevo/dashcore-lib": "~0.19.39",
17
+ "levelup": "^4.4.0",
18
+ "memdown": "^5.1.0"
19
19
  },
20
20
  "devDependencies": {
21
- "eslint": "^5.16.0",
22
- "eslint-config-airbnb-base": "^13.1.0",
23
- "eslint-plugin-import": "^2.17.3",
24
- "mocha": "^5.2.0",
21
+ "eslint": "^7.32.0",
22
+ "eslint-config-airbnb-base": "^14.2.1",
23
+ "eslint-plugin-import": "^2.24.2",
24
+ "mocha": "^9.1.2",
25
25
  "should": "^13.2.3"
26
26
  }
27
- }
27
+ }
@@ -213,4 +213,4 @@ const headers = [
213
213
  },
214
214
  ];
215
215
 
216
- module.exports = headers.map(h => utils.normalizeHeader(h));
216
+ module.exports = headers.map((h) => utils.normalizeHeader(h));
package/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- os: linux
2
- language: node_js
3
- node_js:
4
- - '8'
5
- install:
6
- - npm install
7
- before_install:
8
- - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
9
- before_script:
10
- - npm run lint