|
1 |
| -import {HashComputationLevel, LeafNode, Node, Tree, merkleizeInto} from "@chainsafe/persistent-merkle-tree"; |
| 1 | +import {HashComputationLevel, LeafNode, Node, Tree, merkleizeBlocksBytes} from "@chainsafe/persistent-merkle-tree"; |
2 | 2 | import {ValueOf} from "./abstract";
|
3 | 3 | import {BasicType} from "./basic";
|
4 | 4 | import {ByteViews} from "./composite";
|
@@ -47,11 +47,11 @@ export class ListBasicType<ElementType extends BasicType<unknown>>
|
47 | 47 | readonly maxSize: number;
|
48 | 48 | readonly isList = true;
|
49 | 49 | readonly isViewMutable = true;
|
50 |
| - readonly mixInLengthChunkBytes = new Uint8Array(64); |
| 50 | + readonly mixInLengthBlockBytes = new Uint8Array(64); |
51 | 51 | readonly mixInLengthBuffer = Buffer.from(
|
52 |
| - this.mixInLengthChunkBytes.buffer, |
53 |
| - this.mixInLengthChunkBytes.byteOffset, |
54 |
| - this.mixInLengthChunkBytes.byteLength |
| 52 | + this.mixInLengthBlockBytes.buffer, |
| 53 | + this.mixInLengthBlockBytes.byteOffset, |
| 54 | + this.mixInLengthBlockBytes.byteLength |
55 | 55 | );
|
56 | 56 | protected readonly defaultLen = 0;
|
57 | 57 |
|
@@ -193,34 +193,34 @@ export class ListBasicType<ElementType extends BasicType<unknown>>
|
193 | 193 | }
|
194 | 194 | }
|
195 | 195 |
|
196 |
| - super.hashTreeRootInto(value, this.mixInLengthChunkBytes, 0); |
| 196 | + super.hashTreeRootInto(value, this.mixInLengthBlockBytes, 0); |
197 | 197 | // mixInLength
|
198 | 198 | this.mixInLengthBuffer.writeUIntLE(value.length, 32, 6);
|
199 | 199 | // one for hashTreeRoot(value), one for length
|
200 | 200 | const chunkCount = 2;
|
201 |
| - merkleizeInto(this.mixInLengthChunkBytes, chunkCount, output, offset); |
| 201 | + merkleizeBlocksBytes(this.mixInLengthBlockBytes, chunkCount, output, offset); |
202 | 202 |
|
203 | 203 | if (this.cachePermanentRootStruct) {
|
204 | 204 | cacheRoot(value as ValueWithCachedPermanentRoot, output, offset, safeCache);
|
205 | 205 | }
|
206 | 206 | }
|
207 | 207 |
|
208 |
| - protected getChunkBytes(value: ValueOf<ElementType>[]): Uint8Array { |
| 208 | + protected getBlocksBytes(value: ValueOf<ElementType>[]): Uint8Array { |
209 | 209 | const byteLen = this.value_serializedSize(value);
|
210 |
| - const chunkByteLen = Math.ceil(byteLen / 64) * 64; |
211 |
| - // reallocate this.verkleBytes if needed |
212 |
| - if (byteLen > this.chunkBytesBuffer.length) { |
| 210 | + const blockByteLen = Math.ceil(byteLen / 64) * 64; |
| 211 | + // reallocate this.blocksBuffer if needed |
| 212 | + if (byteLen > this.blocksBuffer.length) { |
213 | 213 | // pad 1 chunk if maxChunkCount is not even
|
214 |
| - this.chunkBytesBuffer = new Uint8Array(chunkByteLen); |
| 214 | + this.blocksBuffer = new Uint8Array(blockByteLen); |
215 | 215 | }
|
216 |
| - const chunkBytes = this.chunkBytesBuffer.subarray(0, chunkByteLen); |
217 |
| - const uint8Array = chunkBytes.subarray(0, byteLen); |
| 216 | + const blockBytes = this.blocksBuffer.subarray(0, blockByteLen); |
| 217 | + const uint8Array = blockBytes.subarray(0, byteLen); |
218 | 218 | const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength);
|
219 | 219 | value_serializeToBytesArrayBasic(this.elementType, value.length, {uint8Array, dataView}, 0, value);
|
220 | 220 |
|
221 | 221 | // all padding bytes must be zero, this is similar to set zeroHash(0)
|
222 |
| - this.chunkBytesBuffer.subarray(byteLen, chunkByteLen).fill(0); |
223 |
| - return chunkBytes; |
| 222 | + this.blocksBuffer.subarray(byteLen, blockByteLen).fill(0); |
| 223 | + return blockBytes; |
224 | 224 | }
|
225 | 225 |
|
226 | 226 | // JSON: inherited from ArrayType
|
|
0 commit comments