@leofcoin/chain 1.7.126 → 1.7.127

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.
@@ -4876,11 +4876,17 @@ class State extends Contract {
4876
4876
  let block = await globalThis.peernet.get(hash, 'block');
4877
4877
  if (block !== undefined) {
4878
4878
  block = await new BlockMessage(block);
4879
+ const computedHash = await block.hash();
4880
+ if (computedHash !== hash) {
4881
+ throw new ResolveError(`block hash mismatch for ${hash}`, {
4882
+ cause: new Error('hash does not match payload')
4883
+ });
4884
+ }
4879
4885
  const { index } = block.decoded;
4880
- if (this.#blocks[index] && this.#blocks[index].hash !== block.hash)
4881
- throw `invalid block ${hash} @${index}`;
4882
- if (!(await globalThis.peernet.has(hash)))
4883
- await globalThis.peernet.put(hash, block.encoded, 'block');
4886
+ if (this.#blocks[index] && this.#blocks[index].hash !== computedHash)
4887
+ throw new ResolveError(`invalid block ${computedHash} @${index}`);
4888
+ if (!(await globalThis.peernet.has(computedHash)))
4889
+ await globalThis.peernet.put(computedHash, block.encoded, 'block');
4884
4890
  }
4885
4891
  return block;
4886
4892
  }
package/exports/chain.js CHANGED
@@ -1003,11 +1003,17 @@ class State extends Contract {
1003
1003
  let block = await globalThis.peernet.get(hash, 'block');
1004
1004
  if (block !== undefined) {
1005
1005
  block = await new BlockMessage(block);
1006
+ const computedHash = await block.hash();
1007
+ if (computedHash !== hash) {
1008
+ throw new ResolveError(`block hash mismatch for ${hash}`, {
1009
+ cause: new Error('hash does not match payload')
1010
+ });
1011
+ }
1006
1012
  const { index } = block.decoded;
1007
- if (this.#blocks[index] && this.#blocks[index].hash !== block.hash)
1008
- throw `invalid block ${hash} @${index}`;
1009
- if (!(await globalThis.peernet.has(hash)))
1010
- await globalThis.peernet.put(hash, block.encoded, 'block');
1013
+ if (this.#blocks[index] && this.#blocks[index].hash !== computedHash)
1014
+ throw new ResolveError(`invalid block ${computedHash} @${index}`);
1015
+ if (!(await globalThis.peernet.has(computedHash)))
1016
+ await globalThis.peernet.put(computedHash, block.encoded, 'block');
1011
1017
  }
1012
1018
  return block;
1013
1019
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.126",
3
+ "version": "1.7.127",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {