Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@chainsafe/ssz

Package Overview
Dependencies
Maintainers
6
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/ssz - npm Package Compare versions

Comparing version 0.14.3 to 0.15.1

lib/type/listUintNum64.d.ts

30

CHANGELOG.md

@@ -6,2 +6,32 @@ # Change Log

## [0.15.1](https://github.com/ChainSafe/ssz/compare/ssz-v0.15.0...ssz-v0.15.1) (2024-03-15)
### Bug Fixes
* export ListUintNum64Type ([#353](https://github.com/ChainSafe/ssz/issues/353)) ([30e3deb](https://github.com/ChainSafe/ssz/commit/30e3debbaf7346711eb201740c072aab645d3b14))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @chainsafe/persistent-merkle-tree bumped to 0.7.1
## [0.15.0](https://github.com/ChainSafe/ssz/compare/ssz-v0.14.3...ssz-v0.15.0) (2024-03-12)
### Features
* add capability to cache merkle roots for lists ([#349](https://github.com/ChainSafe/ssz/issues/349)) ([14c4457](https://github.com/ChainSafe/ssz/commit/14c4457026a9fbea5bfe5c66580f7c8a8bee790a))
* improve ViewDU.serialize() ([#350](https://github.com/ChainSafe/ssz/issues/350)) ([4ba45d3](https://github.com/ChainSafe/ssz/commit/4ba45d3afec08a8aaf853237c3cd8439ca62bca5))
* new type for list of uint64 ([#352](https://github.com/ChainSafe/ssz/issues/352)) ([e131b5a](https://github.com/ChainSafe/ssz/commit/e131b5a9080f8719d624df97d8a4462081a65807))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @chainsafe/persistent-merkle-tree bumped to 0.7.0
## [0.14.3](https://github.com/ChainSafe/ssz/compare/ssz-v0.14.2...ssz-v0.14.3) (2024-02-10)

@@ -8,0 +38,0 @@

6

lib/index.d.ts

@@ -16,13 +16,15 @@ export { BitListType, deserializeUint8ArrayBitListFromBytes } from "./type/bitList";

export { VectorCompositeType } from "./type/vectorComposite";
export { ListUintNum64Type } from "./type/listUintNum64";
export { ArrayType } from "./type/array";
export { BitArrayType } from "./type/bitArray";
export { ByteArrayType } from "./type/byteArray";
export { Type, ValueOf, JsonPath } from "./type/abstract";
export { Type, ValueOf, JsonPath, ByteViews } from "./type/abstract";
export { BasicType, isBasicType } from "./type/basic";
export { CompositeType, CompositeTypeAny, CompositeView, CompositeViewDU, isCompositeType } from "./type/composite";
export { TreeView } from "./view/abstract";
export { ValueOfFields } from "./view/container";
export { TreeViewDU } from "./viewDU/abstract";
export { BitArray, getUint8ByteToBitBooleanArray } from "./value/bitArray";
export { fromHexString, toHexString, byteArrayEquals } from "./util/byteArray";
export { hash64 } from "./util/merkleize";
export { hash64, symbolCachedPermanentRoot } from "./util/merkleize";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hash64 = exports.byteArrayEquals = exports.toHexString = exports.fromHexString = exports.getUint8ByteToBitBooleanArray = exports.BitArray = exports.TreeViewDU = exports.TreeView = exports.isCompositeType = exports.CompositeType = exports.isBasicType = exports.BasicType = exports.Type = exports.ByteArrayType = exports.BitArrayType = exports.ArrayType = exports.VectorCompositeType = exports.VectorBasicType = exports.OptionalType = exports.UnionType = exports.UintNumberType = exports.UintBigintType = exports.NoneType = exports.ListCompositeType = exports.ListBasicType = exports.ContainerNodeStructType = exports.ContainerType = exports.ByteVectorType = exports.ByteListType = exports.BooleanType = exports.BitVectorType = exports.deserializeUint8ArrayBitListFromBytes = exports.BitListType = void 0;
exports.symbolCachedPermanentRoot = exports.hash64 = exports.byteArrayEquals = exports.toHexString = exports.fromHexString = exports.getUint8ByteToBitBooleanArray = exports.BitArray = exports.TreeViewDU = exports.TreeView = exports.isCompositeType = exports.CompositeType = exports.isBasicType = exports.BasicType = exports.Type = exports.ByteArrayType = exports.BitArrayType = exports.ArrayType = exports.ListUintNum64Type = exports.VectorCompositeType = exports.VectorBasicType = exports.OptionalType = exports.UnionType = exports.UintNumberType = exports.UintBigintType = exports.NoneType = exports.ListCompositeType = exports.ListBasicType = exports.ContainerNodeStructType = exports.ContainerType = exports.ByteVectorType = exports.ByteListType = exports.BooleanType = exports.BitVectorType = exports.deserializeUint8ArrayBitListFromBytes = exports.BitListType = void 0;
// Types

@@ -37,2 +37,4 @@ var bitList_1 = require("./type/bitList");

Object.defineProperty(exports, "VectorCompositeType", { enumerable: true, get: function () { return vectorComposite_1.VectorCompositeType; } });
var listUintNum64_1 = require("./type/listUintNum64");
Object.defineProperty(exports, "ListUintNum64Type", { enumerable: true, get: function () { return listUintNum64_1.ListUintNum64Type; } });
// Base types

@@ -69,2 +71,3 @@ var array_1 = require("./type/array");

Object.defineProperty(exports, "hash64", { enumerable: true, get: function () { return merkleize_1.hash64; } });
Object.defineProperty(exports, "symbolCachedPermanentRoot", { enumerable: true, get: function () { return merkleize_1.symbolCachedPermanentRoot; } });
//# sourceMappingURL=index.js.map

@@ -11,3 +11,3 @@ import { Node } from "@chainsafe/persistent-merkle-tree";

protected abstract readonly defaultLen: number;
constructor(elementType: ElementType);
constructor(elementType: ElementType, cachePermanentRootStruct?: boolean);
defaultValue(): ValueOf<ElementType>[];

@@ -14,0 +14,0 @@ abstract tree_getLength(node: Node): number;

@@ -12,4 +12,4 @@ "use strict";

class ArrayType extends composite_1.CompositeType {
constructor(elementType) {
super();
constructor(elementType, cachePermanentRootStruct) {
super(cachePermanentRootStruct);
this.elementType = elementType;

@@ -16,0 +16,0 @@ }

@@ -32,3 +32,3 @@ import { Node } from "@chainsafe/persistent-merkle-tree";

*/
export declare function tree_serializeToBytesArrayBasic<ElementType extends BasicType<unknown>>(elementType: ElementType, length: number, depth: number, output: ByteViews, offset: number, node: Node): number;
export declare function tree_serializeToBytesArrayBasic<ElementType extends BasicType<unknown>>(elementType: ElementType, length: number, depth: number, output: ByteViews, offset: number, node: Node, cachedNodes?: Node[] | null): number;
export declare function tree_deserializeFromBytesArrayBasic<ElementType extends BasicType<unknown>>(elementType: ElementType, chunkDepth: number, data: ByteViews, start: number, end: number, arrayProps: ArrayProps): Node;

@@ -35,0 +35,0 @@ /**

@@ -71,6 +71,6 @@ "use strict";

*/
function tree_serializeToBytesArrayBasic(elementType, length, depth, output, offset, node) {
function tree_serializeToBytesArrayBasic(elementType, length, depth, output, offset, node, cachedNodes = null) {
const size = elementType.byteLength * length;
const chunkCount = Math.ceil(size / 32);
const nodes = persistent_merkle_tree_1.getNodesAtDepth(node, depth, 0, chunkCount);
const nodes = cachedNodes ?? persistent_merkle_tree_1.getNodesAtDepth(node, depth, 0, chunkCount);
persistent_merkle_tree_1.packedNodeRootsToBytes(output.dataView, offset, size, nodes);

@@ -77,0 +77,0 @@ return offset + size;

@@ -26,3 +26,3 @@ import { Node } from "@chainsafe/persistent-merkle-tree";

*/
export declare function tree_serializeToBytesArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(elementType: ElementType, length: number, depth: number, node: Node, output: ByteViews, offset: number): number;
export declare function tree_serializeToBytesArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(elementType: ElementType, length: number, depth: number, node: Node, output: ByteViews, offset: number, cachedNodes?: Node[] | null): number;
export declare function tree_deserializeFromBytesArrayComposite<ElementType extends CompositeType<unknown, unknown, unknown>>(elementType: ElementType, chunkDepth: number, data: ByteViews, start: number, end: number, arrayProps: ArrayProps): Node;

@@ -29,0 +29,0 @@ /**

@@ -103,4 +103,4 @@ "use strict";

*/
function tree_serializeToBytesArrayComposite(elementType, length, depth, node, output, offset) {
const nodes = persistent_merkle_tree_1.getNodesAtDepth(node, depth, 0, length);
function tree_serializeToBytesArrayComposite(elementType, length, depth, node, output, offset, cachedNodes = null) {
const nodes = cachedNodes ?? persistent_merkle_tree_1.getNodesAtDepth(node, depth, 0, length);
// Variable Length

@@ -107,0 +107,0 @@ // Indices contain offsets, which are indices deeper in the byte array

@@ -21,3 +21,3 @@ import { Gindex, Node, Proof, Tree } from "@chainsafe/persistent-merkle-tree";

*/
private readonly cachePermanentRootStruct?;
protected readonly cachePermanentRootStruct?: boolean | undefined;
readonly isBasic = false;

@@ -24,0 +24,0 @@ /**

@@ -10,4 +10,2 @@ "use strict";

exports.LENGTH_GINDEX = BigInt(3);
/** Dedicated property to cache hashTreeRoot of immutable CompositeType values */
const symbolCachedPermanentRoot = Symbol("ssz_cached_permanent_root");
/* eslint-disable @typescript-eslint/member-ordering */

@@ -108,3 +106,3 @@ /**

if (this.cachePermanentRootStruct) {
const cachedRoot = value[symbolCachedPermanentRoot];
const cachedRoot = value[merkleize_1.symbolCachedPermanentRoot];
if (cachedRoot) {

@@ -116,3 +114,3 @@ return cachedRoot;

if (this.cachePermanentRootStruct) {
value[symbolCachedPermanentRoot] = root;
value[merkleize_1.symbolCachedPermanentRoot] = root;
}

@@ -123,3 +121,3 @@ return root;

getCachedPermanentRoot(value) {
return value[symbolCachedPermanentRoot];
return value[merkleize_1.symbolCachedPermanentRoot];
}

@@ -126,0 +124,0 @@ // Proofs API

@@ -40,2 +40,4 @@ import { Node, Tree, Gindex } from "@chainsafe/persistent-merkle-tree";

readonly fieldsEntries: FieldEntry<Fields>[];
/** End of fixed section of serialized Container */
readonly fixedEnd: number;
protected readonly fieldsGindex: Record<keyof Fields, Gindex>;

@@ -47,4 +49,2 @@ protected readonly jsonKeyToFieldName: Record<string, keyof Fields>;

protected readonly variableOffsetsPosition: number[];
/** End of fixed section of serialized Container */
protected readonly fixedEnd: number;
/** Cached TreeView constuctor with custom prototype for this Type's properties */

@@ -51,0 +51,0 @@ protected readonly TreeView: ContainerTreeViewTypeConstructor<Fields>;

@@ -12,2 +12,3 @@ import { Node, Tree } from "@chainsafe/persistent-merkle-tree";

typeName?: string;
cachePermanentRootStruct?: boolean;
}

@@ -14,0 +15,0 @@ /**

@@ -19,3 +19,3 @@ "use strict";

constructor(elementType, limit, opts) {
super(elementType);
super(elementType, opts?.cachePermanentRootStruct);
this.elementType = elementType;

@@ -98,3 +98,14 @@ this.limit = limit;

hashTreeRoot(value) {
return merkleize_1.mixInLength(super.hashTreeRoot(value), value.length);
// Return cached mutable root if any
if (this.cachePermanentRootStruct) {
const cachedRoot = value[merkleize_1.symbolCachedPermanentRoot];
if (cachedRoot) {
return cachedRoot;
}
}
const root = merkleize_1.mixInLength(super.hashTreeRoot(value), value.length);
if (this.cachePermanentRootStruct) {
value[merkleize_1.symbolCachedPermanentRoot] = root;
}
return root;
}

@@ -101,0 +112,0 @@ getRoots(value) {

@@ -11,2 +11,3 @@ import { Node, Tree } from "@chainsafe/persistent-merkle-tree";

typeName?: string;
cachePermanentRootStruct?: boolean;
}

@@ -13,0 +14,0 @@ /**

@@ -20,3 +20,3 @@ "use strict";

constructor(elementType, limit, opts) {
super(elementType);
super(elementType, opts?.cachePermanentRootStruct);
this.elementType = elementType;

@@ -101,3 +101,14 @@ this.limit = limit;

hashTreeRoot(value) {
return merkleize_1.mixInLength(super.hashTreeRoot(value), value.length);
// Return cached mutable root if any
if (this.cachePermanentRootStruct) {
const cachedRoot = value[merkleize_1.symbolCachedPermanentRoot];
if (cachedRoot) {
return cachedRoot;
}
}
const root = merkleize_1.mixInLength(super.hashTreeRoot(value), value.length);
if (this.cachePermanentRootStruct) {
value[merkleize_1.symbolCachedPermanentRoot] = root;
}
return root;
}

@@ -104,0 +115,0 @@ getRoots(value) {

@@ -0,1 +1,7 @@

/** Dedicated property to cache hashTreeRoot of immutable CompositeType values */
export declare const symbolCachedPermanentRoot: unique symbol;
/** Helper type to cast CompositeType values that may have @see symbolCachedPermanentRoot */
export declare type ValueWithCachedPermanentRoot = {
[symbolCachedPermanentRoot]?: Uint8Array;
};
export declare function hash64(bytes32A: Uint8Array, bytes32B: Uint8Array): Uint8Array;

@@ -2,0 +8,0 @@ export declare function merkleize(chunks: Uint8Array[], padFor: number): Uint8Array;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.nextPowerOf2 = exports.maxChunksToDepth = exports.bitLength = exports.mixInLength = exports.splitIntoRootChunks = exports.merkleize = exports.hash64 = void 0;
exports.nextPowerOf2 = exports.maxChunksToDepth = exports.bitLength = exports.mixInLength = exports.splitIntoRootChunks = exports.merkleize = exports.hash64 = exports.symbolCachedPermanentRoot = void 0;
const index_1 = require("@chainsafe/persistent-merkle-tree/lib/hasher/index");
const zeros_1 = require("./zeros");
/** Dedicated property to cache hashTreeRoot of immutable CompositeType values */
exports.symbolCachedPermanentRoot = Symbol("ssz_cached_permanent_root");
function hash64(bytes32A, bytes32B) {

@@ -7,0 +9,0 @@ return index_1.hasher.digest64(bytes32A, bytes32B);

@@ -16,2 +16,3 @@ import { Gindex, Tree } from "@chainsafe/persistent-merkle-tree";

readonly fieldsEntries: FieldEntry<Fields>[];
readonly fixedEnd: number;
};

@@ -18,0 +19,0 @@ export declare type ValueOfFields<Fields extends Record<string, Type<unknown>>> = {

@@ -1,2 +0,2 @@

import { CompositeType } from "../type/composite";
import { ByteViews, CompositeType } from "../type/composite";
import { TreeView } from "../view/abstract";

@@ -30,2 +30,3 @@ /**

protected abstract clearCache(): void;
serializeToBytes(output: ByteViews, offset: number): number;
/**

@@ -32,0 +33,0 @@ * Merkleize view and compute its hashTreeRoot.

@@ -19,2 +19,8 @@ "use strict";

class TreeViewDU extends abstract_1.TreeView {
/*
* By default use type to serialize ViewDU.
*/
serializeToBytes(output, offset) {
return this.type.tree_serializeToBytes(output, offset, this.node);
}
/**

@@ -37,3 +43,6 @@ * Merkleize view and compute its hashTreeRoot.

this.commit();
return super.serialize();
const output = new Uint8Array(this.type.tree_serializedSize(this.node));
const dataView = new DataView(output.buffer, output.byteOffset, output.byteLength);
this.serializeToBytes({ uint8Array: output, dataView }, 0);
return output;
}

@@ -40,0 +49,0 @@ /**

@@ -55,4 +55,4 @@ import { Node } from "@chainsafe/persistent-merkle-tree";

protected clearCache(): void;
private populateAllNodes;
protected populateAllNodes(): void;
}
//# sourceMappingURL=arrayComposite.d.ts.map

@@ -74,2 +74,39 @@ "use strict";

}
/**
* Same method to `type/container.ts` that call ViewDU.serializeToBytes() of internal fields.
*/
serializeToBytes(output, offset) {
this.commit();
let fixedIndex = offset;
let variableIndex = offset + this.type.fixedEnd;
for (let index = 0; index < this.type.fieldsEntries.length; index++) {
const { fieldType } = this.type.fieldsEntries[index];
let node = this.nodes[index];
if (node === undefined) {
node = persistent_merkle_tree_1.getNodeAtDepth(this._rootNode, this.type.depth, index);
this.nodes[index] = node;
}
if (fieldType.fixedSize === null) {
// write offset
output.dataView.setUint32(fixedIndex, variableIndex - offset, true);
fixedIndex += 4;
// write serialized element to variable section
// basic types always have fixedSize
if (composite_1.isCompositeType(fieldType)) {
const view = fieldType.getViewDU(node, this.caches[index]);
if (view.serializeToBytes !== undefined) {
variableIndex = view.serializeToBytes(output, variableIndex);
}
else {
// some types don't define ViewDU as TreeViewDU, like the UnionType, in that case view.serializeToBytes = undefined
variableIndex = fieldType.tree_serializeToBytes(output, variableIndex, node);
}
}
}
else {
fixedIndex = fieldType.tree_serializeToBytes(output, fixedIndex, node);
}
}
return variableIndex;
}
}

@@ -76,0 +113,0 @@ function getContainerTreeViewDUClass(type) {

import { Node } from "@chainsafe/persistent-merkle-tree";
import { ValueOf } from "../type/abstract";
import { ByteViews, ValueOf } from "../type/abstract";
import { BasicType } from "../type/basic";

@@ -20,3 +20,7 @@ import { ListBasicType } from "../view/listBasic";

sliceTo(index: number): this;
/**
* Same method to `type/listBasic.ts` leveraging cached nodes.
*/
serializeToBytes(output: ByteViews, offset: number): number;
}
//# sourceMappingURL=listBasic.d.ts.map

@@ -6,2 +6,3 @@ "use strict";

const arrayBasic_1 = require("./arrayBasic");
const arrayBasic_2 = require("../type/arrayBasic");
class ListBasicTreeViewDU extends arrayBasic_1.ArrayBasicTreeViewDU {

@@ -65,4 +66,13 @@ constructor(type, _rootNode, cache) {

}
/**
* Same method to `type/listBasic.ts` leveraging cached nodes.
*/
serializeToBytes(output, offset) {
this.commit();
const { nodes, nodesPopulated } = this.cache;
const chunksNode = this.type.tree_getChunksNode(this._rootNode);
return arrayBasic_2.tree_serializeToBytesArrayBasic(this.type.elementType, this._length, this.type.chunkDepth, output, offset, chunksNode, nodesPopulated ? nodes : null);
}
}
exports.ListBasicTreeViewDU = ListBasicTreeViewDU;
//# sourceMappingURL=listBasic.js.map
import { Node } from "@chainsafe/persistent-merkle-tree";
import { ValueOf } from "../type/abstract";
import { ByteViews, ValueOf } from "../type/abstract";
import { CompositeType, CompositeView, CompositeViewDU } from "../type/composite";

@@ -28,3 +28,7 @@ import { ListCompositeType } from "../view/listComposite";

sliceTo(index: number): this;
/**
* Same method to `type/listComposite.ts` leveraging cached nodes.
*/
serializeToBytes(output: ByteViews, offset: number): number;
}
//# sourceMappingURL=listComposite.d.ts.map

@@ -6,2 +6,3 @@ "use strict";

const arrayComposite_1 = require("./arrayComposite");
const arrayComposite_2 = require("../type/arrayComposite");
class ListCompositeTreeViewDU extends arrayComposite_1.ArrayCompositeTreeViewDU {

@@ -42,3 +43,3 @@ constructor(type, _rootNode, cache) {

const rootNode = this._rootNode;
const length = this.type.tree_getLength(rootNode);
const length = this._length;
// All nodes beyond length are already zero

@@ -57,4 +58,13 @@ // Array of length 2: [X,X,0,0], for index >= 1 no action needed

}
/**
* Same method to `type/listComposite.ts` leveraging cached nodes.
*/
serializeToBytes(output, offset) {
this.commit();
this.populateAllNodes();
const chunksNode = this.type.tree_getChunksNode(this._rootNode);
return arrayComposite_2.tree_serializeToBytesArrayComposite(this.type.elementType, this._length, this.type.chunkDepth, chunksNode, output, offset, this.nodes);
}
}
exports.ListCompositeTreeViewDU = ListCompositeTreeViewDU;
//# sourceMappingURL=listComposite.js.map

@@ -7,3 +7,3 @@ {

"homepage": "https://github.com/chainsafe/ssz",
"version": "0.14.3",
"version": "0.15.1",
"main": "lib/index.js",

@@ -40,3 +40,3 @@ "files": [

"@chainsafe/as-sha256": "^0.4.1",
"@chainsafe/persistent-merkle-tree": "^0.6.1"
"@chainsafe/persistent-merkle-tree": "^0.7.1"
},

@@ -43,0 +43,0 @@ "devDependencies": {

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc