@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.
- package/exports/browser/chain.js +10 -4
- package/exports/chain.js +10 -4
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -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 !==
|
|
4881
|
-
throw `invalid block ${
|
|
4882
|
-
if (!(await globalThis.peernet.has(
|
|
4883
|
-
await globalThis.peernet.put(
|
|
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 !==
|
|
1008
|
-
throw `invalid block ${
|
|
1009
|
-
if (!(await globalThis.peernet.has(
|
|
1010
|
-
await globalThis.peernet.put(
|
|
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
|
}
|