@chainsafe/ssz
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -6,2 +6,11 @@ # Change Log | ||
## [0.9.1](https://github.com/chainsafe/ssz/compare/@chainsafe/ssz@0.9.0...@chainsafe/ssz@0.9.1) (2022-04-14) | ||
* Force usage of Uint8Array.prototype.slice (#258) | ||
* Add and use a new helper to digest64 two 32 bytes (#255) | ||
* Remove unused files (#248) | ||
* Bump spec tests (#251) | ||
* Bump yargs-parser from 16.1.0 to 20.2.4 in /packages/ssz (#189) | ||
* Test empty ByteListType (#250) | ||
# [0.9.0](http://chainsafe/ssz/compare/@chainsafe/ssz@0.8.19...@chainsafe/ssz@0.9.0) (2022-03-24) | ||
@@ -8,0 +17,0 @@ |
@@ -38,2 +38,8 @@ "use strict"; | ||
deserialize(uint8Array) { | ||
// Buffer.prototype.slice does not copy memory, force use Uint8Array.prototype.slice https://github.com/nodejs/node/issues/28087 | ||
// - Uint8Array.prototype.slice: Copy memory, safe to mutate | ||
// - Buffer.prototype.slice: Does NOT copy memory, mutation affects both views | ||
// We could ensure that all Buffer instances are converted to Uint8Array before calling value_deserializeFromBytes | ||
// However doing that in a browser friendly way is not easy. Downstream code uses `Uint8Array.prototype.slice.call` | ||
// to ensure Buffer.prototype.slice is never used. Unit tests also test non-mutability. | ||
const dataView = new DataView(uint8Array.buffer, uint8Array.byteOffset, uint8Array.byteLength); | ||
@@ -40,0 +46,0 @@ return this.value_deserializeFromBytes({ uint8Array, dataView }, 0, uint8Array.length); |
@@ -99,3 +99,4 @@ "use strict"; | ||
if (lastByte === 1) { | ||
const uint8Array = data.slice(start, end - 1); | ||
// Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 | ||
const uint8Array = Uint8Array.prototype.slice.call(data, start, end - 1); | ||
const bitLen = (size - 1) * 8; | ||
@@ -105,3 +106,4 @@ return { uint8Array, bitLen }; | ||
// the last byte is > 1, so a padding bit will exist in the last byte and need to be removed | ||
const uint8Array = data.slice(start, end); | ||
// Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 | ||
const uint8Array = Uint8Array.prototype.slice.call(data, start, end); | ||
// mask lastChunkByte | ||
@@ -108,0 +110,0 @@ const lastByteBitLength = lastByte.toString(2).length - 1; |
@@ -47,3 +47,4 @@ "use strict"; | ||
this.assertValidLength(data.uint8Array, start, end); | ||
return new bitArray_1.BitArray(data.uint8Array.slice(start, end), this.lengthBits); | ||
// Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 | ||
return new bitArray_1.BitArray(Uint8Array.prototype.slice.call(data.uint8Array, start, end), this.lengthBits); | ||
} | ||
@@ -50,0 +51,0 @@ tree_serializedSize() { |
import { Gindex, Node, Tree } from "@chainsafe/persistent-merkle-tree"; | ||
import { ByteViews } from "./abstract"; | ||
import { CompositeType } from "./composite"; | ||
@@ -23,2 +24,4 @@ export declare type ByteArray = Uint8Array; | ||
toViewDU(value: ByteArray): ByteArray; | ||
value_serializeToBytes(output: ByteViews, offset: number, value: ByteArray): number; | ||
value_deserializeFromBytes(data: ByteViews, start: number, end: number): ByteArray; | ||
protected getRoots(value: ByteArray): Uint8Array[]; | ||
@@ -25,0 +28,0 @@ getPropertyGindex(): null; |
@@ -52,2 +52,11 @@ "use strict"; | ||
} | ||
// Serialization + deserialization (only value is generic) | ||
value_serializeToBytes(output, offset, value) { | ||
output.uint8Array.set(value, offset); | ||
return offset + value.length; | ||
} | ||
value_deserializeFromBytes(data, start, end) { | ||
this.assertValidSize(end - start); | ||
return Uint8Array.prototype.slice.call(data.uint8Array, start, end); | ||
} | ||
// Merkleization | ||
@@ -54,0 +63,0 @@ getRoots(value) { |
@@ -28,4 +28,2 @@ import { Node } from "@chainsafe/persistent-merkle-tree"; | ||
value_serializedSize(value: Uint8Array): number; | ||
value_serializeToBytes(output: ByteViews, offset: number, value: ByteArray): number; | ||
value_deserializeFromBytes(data: ByteViews, start: number, end: number): ByteArray; | ||
tree_serializedSize(node: Node): number; | ||
@@ -32,0 +30,0 @@ tree_serializeToBytes(output: ByteViews, offset: number, node: Node): number; |
@@ -41,10 +41,3 @@ "use strict"; | ||
} | ||
value_serializeToBytes(output, offset, value) { | ||
output.uint8Array.set(value, offset); | ||
return offset + value.length; | ||
} | ||
value_deserializeFromBytes(data, start, end) { | ||
this.assertValidSize(end - start); | ||
return data.uint8Array.slice(start, end); | ||
} | ||
// value_* inherited from ByteArrayType | ||
tree_serializedSize(node) { | ||
@@ -51,0 +44,0 @@ return arrayBasic_1.getLengthFromRootNode(node); |
@@ -29,4 +29,2 @@ import { Node } from "@chainsafe/persistent-merkle-tree"; | ||
value_serializedSize(): number; | ||
value_serializeToBytes(output: ByteViews, offset: number, value: ByteVector): number; | ||
value_deserializeFromBytes(data: ByteViews, start: number, end: number): ByteVector; | ||
tree_serializedSize(): number; | ||
@@ -33,0 +31,0 @@ tree_serializeToBytes(output: ByteViews, offset: number, node: Node): number; |
@@ -40,10 +40,3 @@ "use strict"; | ||
} | ||
value_serializeToBytes(output, offset, value) { | ||
output.uint8Array.set(value, offset); | ||
return offset + this.fixedSize; | ||
} | ||
value_deserializeFromBytes(data, start, end) { | ||
this.assertValidSize(end - start); | ||
return data.uint8Array.slice(start, end); | ||
} | ||
// value_* inherited from ByteArrayType | ||
tree_serializedSize() { | ||
@@ -50,0 +43,0 @@ return this.fixedSize; |
@@ -7,3 +7,3 @@ "use strict"; | ||
function hash64(bytes32A, bytes32B) { | ||
return as_sha256_1.digest64(Buffer.concat([bytes32A, bytes32B])); | ||
return as_sha256_1.digest2Bytes32(bytes32A, bytes32B); | ||
} | ||
@@ -10,0 +10,0 @@ exports.hash64 = hash64; |
@@ -10,3 +10,3 @@ "use strict"; | ||
for (let i = zeroHashes.length; i <= depth; i++) { | ||
zeroHashes[i] = as_sha256_1.digest64(Buffer.concat([zeroHashes[i - 1], zeroHashes[i - 1]])); | ||
zeroHashes[i] = as_sha256_1.digest2Bytes32(zeroHashes[i - 1], zeroHashes[i - 1]); | ||
} | ||
@@ -13,0 +13,0 @@ } |
@@ -54,3 +54,4 @@ "use strict"; | ||
// TODO: Benchmark if Uint8Array.slice(0) is the fastest way to copy data here | ||
return new BitArray(this.uint8Array.slice(0), this.bitLen); | ||
// Buffer.prototype.slice does not copy memory, Enforce Uint8Array usage https://github.com/nodejs/node/issues/28087 | ||
return new BitArray(Uint8Array.prototype.slice.call(this.uint8Array, 0), this.bitLen); | ||
} | ||
@@ -57,0 +58,0 @@ /** |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/chainsafe/ssz", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"main": "lib/index.js", | ||
@@ -39,4 +39,4 @@ "files": [ | ||
"dependencies": { | ||
"@chainsafe/as-sha256": "^0.3.0", | ||
"@chainsafe/persistent-merkle-tree": "^0.4.0", | ||
"@chainsafe/as-sha256": "^0.3.1", | ||
"@chainsafe/persistent-merkle-tree": "^0.4.1", | ||
"case": "^1.6.3" | ||
@@ -55,3 +55,3 @@ }, | ||
], | ||
"gitHead": "59065e6965a04d829d49dfaa870f237a38280c4e" | ||
"gitHead": "42c30c4c797ef1ec06ef0139d4967c4725dca4e7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
461365
6906
0