Socket
Socket
Sign inDemoInstall

@chainsafe/ssz

Package Overview
Dependencies
Maintainers
5
Versions
71
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.9.2 to 0.9.3

lib/util/named.d.ts

8

CHANGELOG.md

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

## [0.9.3](http://chainsafe/ssz/compare/@chainsafe/ssz@0.9.2...@chainsafe/ssz@0.9.3) (2022-12-08)
**Note:** Version bump only for package @chainsafe/ssz
## [0.9.2](https://github.com/chainsafe/ssz/compare/@chainsafe/ssz@0.9.1...@chainsafe/ssz@0.9.2) (2022-05-31)

@@ -8,0 +16,0 @@

7

lib/type/bitList.d.ts
import { Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./composite";
import { BitArray } from "../value/bitArray";
import { BitArrayType } from "./bitArray";
export interface BitListOptions {
typeName?: string;
}
/**

@@ -22,3 +26,4 @@ * BitList: ordered variable-length collection of boolean values, limited to N bits

readonly isList = true;
constructor(limitBits: number);
constructor(limitBits: number, opts?: BitListOptions);
static named(limitBits: number, opts: Require<BitListOptions, "typeName">): BitListType;
defaultValue(): BitArray;

@@ -25,0 +30,0 @@ value_serializedSize(value: BitArray): number;

9

lib/type/bitList.js

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const arrayBasic_1 = require("./arrayBasic");
const bitArray_1 = require("../value/bitArray");
const bitArray_2 = require("./bitArray");
/* eslint-disable @typescript-eslint/member-ordering */
/**

@@ -19,3 +19,3 @@ * BitList: ordered variable-length collection of boolean values, limited to N bits

class BitListType extends bitArray_2.BitArrayType {
constructor(limitBits) {
constructor(limitBits, opts) {
super();

@@ -28,3 +28,3 @@ this.limitBits = limitBits;

throw Error("List limit must be > 0");
this.typeName = `BitList[${limitBits}]`;
this.typeName = opts?.typeName ?? `BitList[${limitBits}]`;
// TODO Check that itemsPerChunk is an integer

@@ -37,2 +37,5 @@ this.maxChunkCount = Math.ceil(this.limitBits / 8 / 32);

}
static named(limitBits, opts) {
return new (named_1.namedClass(BitListType, opts.typeName))(limitBits, opts);
}
defaultValue() {

@@ -39,0 +42,0 @@ return bitArray_1.BitArray.fromBitLen(0);

import { Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./composite";
import { BitArray } from "../value/bitArray";
import { BitArrayType } from "./bitArray";
export interface BitVectorOptions {
typeName?: string;
}
/**

@@ -33,3 +37,4 @@ * BitVector: ordered fixed-length collection of boolean values, with N bits

private readonly zeroBitsMask;
constructor(lengthBits: number);
constructor(lengthBits: number, opts?: BitVectorOptions);
static named(limitBits: number, opts: Require<BitVectorOptions, "typeName">): BitVectorType;
defaultValue(): BitArray;

@@ -36,0 +41,0 @@ value_serializedSize(): number;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const bitArray_1 = require("../value/bitArray");
const bitArray_2 = require("./bitArray");
/* eslint-disable @typescript-eslint/member-ordering */
/**

@@ -18,3 +18,3 @@ * BitVector: ordered fixed-length collection of boolean values, with N bits

class BitVectorType extends bitArray_2.BitArrayType {
constructor(lengthBits) {
constructor(lengthBits, opts) {
super();

@@ -25,3 +25,3 @@ this.lengthBits = lengthBits;

throw Error("Vector length must be > 0");
this.typeName = `BitVector[${lengthBits}]`;
this.typeName = opts?.typeName ?? `BitVector[${lengthBits}]`;
this.chunkCount = Math.ceil(this.lengthBits / 8 / 32);

@@ -36,2 +36,5 @@ this.maxChunkCount = this.chunkCount;

}
static named(limitBits, opts) {
return new (named_1.namedClass(BitVectorType, opts.typeName))(limitBits, opts);
}
defaultValue() {

@@ -38,0 +41,0 @@ return bitArray_1.BitArray.fromBitLen(this.lengthBits);

import { LeafNode, Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./abstract";
import { BasicType } from "./basic";
export interface BooleanOpts {
typeName?: string;
}
/**

@@ -9,3 +13,3 @@ * Boolean: True or False

export declare class BooleanType extends BasicType<boolean> {
readonly typeName = "boolean";
readonly typeName: string;
readonly byteLength = 1;

@@ -16,2 +20,4 @@ readonly itemsPerChunk = 32;

readonly maxSize = 1;
constructor(opts?: BooleanOpts);
static named(opts: Require<BooleanOpts, "typeName">): BooleanType;
defaultValue(): boolean;

@@ -18,0 +24,0 @@ value_serializeToBytes(output: ByteViews, offset: number, value: boolean): number;

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

const persistent_merkle_tree_1 = require("@chainsafe/persistent-merkle-tree");
const named_1 = require("../util/named");
const basic_1 = require("./basic");
/* eslint-disable @typescript-eslint/member-ordering */
/**

@@ -13,5 +13,4 @@ * Boolean: True or False

class BooleanType extends basic_1.BasicType {
constructor() {
super(...arguments);
this.typeName = "boolean";
constructor(opts) {
super();
this.byteLength = 1;

@@ -22,3 +21,7 @@ this.itemsPerChunk = 32;

this.maxSize = 1;
this.typeName = opts?.typeName ?? "boolean";
}
static named(opts) {
return new (named_1.namedClass(BooleanType, opts.typeName))(opts);
}
defaultValue() {

@@ -25,0 +28,0 @@ return false;

import { Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./composite";
import { ByteArrayType, ByteArray } from "./byteArray";
export interface ByteListOptions {
typeName?: string;
}
/**

@@ -26,3 +30,4 @@ * ByteList: Immutable alias of List[byte, N]

readonly isList = true;
constructor(limitBytes: number);
constructor(limitBytes: number, opts?: ByteListOptions);
static named(limitBits: number, opts: Require<ByteListOptions, "typeName">): ByteListType;
value_serializedSize(value: Uint8Array): number;

@@ -29,0 +34,0 @@ tree_serializedSize(node: Node): number;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const arrayBasic_1 = require("./arrayBasic");
const byteArray_1 = require("./byteArray");
/* eslint-disable @typescript-eslint/member-ordering */
/**

@@ -23,3 +23,3 @@ * ByteList: Immutable alias of List[byte, N]

class ByteListType extends byteArray_1.ByteArrayType {
constructor(limitBytes) {
constructor(limitBytes, opts) {
super();

@@ -31,3 +31,3 @@ this.limitBytes = limitBytes;

throw Error("List limit must be > 0");
this.typeName = `ByteList[${limitBytes}]`;
this.typeName = opts?.typeName ?? `ByteList[${limitBytes}]`;
this.maxChunkCount = Math.ceil(this.limitBytes / 32);

@@ -39,2 +39,5 @@ this.chunkDepth = merkleize_1.maxChunksToDepth(this.maxChunkCount);

}
static named(limitBits, opts) {
return new (named_1.namedClass(ByteListType, opts.typeName))(limitBits, opts);
}
// Views: inherited from ByteArrayType

@@ -41,0 +44,0 @@ // Serialization + deserialization

import { Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./composite";
import { ByteArrayType } from "./byteArray";
export declare type ByteVector = Uint8Array;
export interface ByteVectorOptions {
typeName?: string;
}
/**

@@ -27,3 +31,4 @@ * ByteVector: Immutable alias of Vector[byte, N]

readonly isList = false;
constructor(lengthBytes: number);
constructor(lengthBytes: number, opts?: ByteVectorOptions);
static named(limitBits: number, opts: Require<ByteVectorOptions, "typeName">): ByteVectorType;
value_serializedSize(): number;

@@ -30,0 +35,0 @@ tree_serializedSize(): number;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const byteArray_1 = require("./byteArray");

@@ -22,3 +23,3 @@ /* eslint-disable @typescript-eslint/member-ordering */

class ByteVectorType extends byteArray_1.ByteArrayType {
constructor(lengthBytes) {
constructor(lengthBytes, opts) {
super();

@@ -29,3 +30,3 @@ this.lengthBytes = lengthBytes;

throw Error("Vector length must be > 0");
this.typeName = `ByteVector[${lengthBytes}]`;
this.typeName = opts?.typeName ?? `ByteVector[${lengthBytes}]`;
this.maxChunkCount = Math.ceil(this.lengthBytes / 32);

@@ -38,2 +39,5 @@ this.chunkDepth = merkleize_1.maxChunksToDepth(this.maxChunkCount);

}
static named(limitBits, opts) {
return new (named_1.namedClass(ByteVectorType, opts.typeName))(limitBits, opts);
}
// Views: inherited from ByteArrayType

@@ -40,0 +44,0 @@ // Serialization + deserialization

import { Node, Tree, Gindex } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { Type } from "./abstract";

@@ -51,2 +52,3 @@ import { CompositeType, ByteViews } from "./composite";

constructor(fields: Fields, opts?: ContainerOptions<Fields> | undefined);
static named<Fields extends Record<string, Type<unknown>>>(fields: Fields, opts: Require<ContainerOptions<Fields>, "typeName">): ContainerType<Fields>;
defaultValue(): ValueOfFields<Fields>;

@@ -53,0 +55,0 @@ getView(tree: Tree): ContainerTreeViewType<Fields>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const composite_1 = require("./composite");

@@ -66,2 +67,5 @@ const container_1 = require("../view/container");

}
static named(fields, opts) {
return new (named_1.namedClass(ContainerType, opts.typeName))(fields, opts);
}
defaultValue() {

@@ -131,3 +135,2 @@ const value = {};

const fieldRange = fieldRanges[i];
// TODO: Consider adding SszErrorPath back but preserving the original stack-traces
value[fieldName] = fieldType.value_deserializeFromBytes(data, start + fieldRange.start, start + fieldRange.end);

@@ -134,0 +137,0 @@ }

import { Node } from "@chainsafe/persistent-merkle-tree";
import { Type, ByteViews } from "./abstract";
import { ContainerType, ContainerOptions } from "./container";
import { Require } from "../util/types";
import { ValueOfFields } from "../view/container";

@@ -22,2 +23,3 @@ /**

constructor(fields: Fields, opts?: ContainerOptions<Fields>);
static named<Fields extends Record<string, Type<unknown>>>(fields: Fields, opts: Require<ContainerOptions<Fields>, "typeName">): ContainerType<Fields>;
tree_serializedSize(node: Node): number;

@@ -24,0 +26,0 @@ tree_serializeToBytes(output: ByteViews, offset: number, node: Node): number;

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

const container_1 = require("./container");
const named_1 = require("../util/named");
const containerNodeStruct_1 = require("../view/containerNodeStruct");

@@ -52,2 +53,5 @@ const containerNodeStruct_2 = require("../viewDU/containerNodeStruct");

}
static named(fields, opts) {
return new (named_1.namedClass(container_1.ContainerType, opts.typeName))(fields, opts);
}
tree_serializedSize(node) {

@@ -54,0 +58,0 @@ return this.value_serializedSize(node.value);

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

import { ByteViews } from "./composite";
import { Require } from "../util/types";
import { ArrayBasicType } from "../view/arrayBasic";

@@ -10,5 +11,5 @@ import { ListBasicTreeView } from "../view/listBasic";

import { ArrayType } from "./array";
export declare type ListBasicOpts = {
export interface ListBasicOpts {
typeName?: string;
};
}
/**

@@ -36,2 +37,3 @@ * List: ordered variable-length homogeneous collection, limited to N values

constructor(elementType: ElementType, limit: number, opts?: ListBasicOpts);
static named<ElementType extends BasicType<unknown>>(elementType: ElementType, limit: number, opts: Require<ListBasicOpts, "typeName">): ListBasicType<ElementType>;
getView(tree: Tree): ListBasicTreeView<ElementType>;

@@ -38,0 +40,0 @@ getViewDU(node: Node, cache?: unknown): ListBasicTreeViewDU<ElementType>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const listBasic_1 = require("../view/listBasic");

@@ -40,2 +41,5 @@ const listBasic_2 = require("../viewDU/listBasic");

}
static named(elementType, limit, opts) {
return new (named_1.namedClass(ListBasicType, opts.typeName))(elementType, limit, opts);
}
getView(tree) {

@@ -42,0 +46,0 @@ return new listBasic_1.ListBasicTreeView(this, tree);

import { Node, Tree } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ValueOf, ByteViews } from "./abstract";

@@ -8,5 +9,5 @@ import { CompositeType, CompositeView, CompositeViewDU } from "./composite";

import { ArrayType } from "./array";
export declare type ListCompositeOpts = {
export interface ListCompositeOpts {
typeName?: string;
};
}
/**

@@ -34,2 +35,3 @@ * List: ordered variable-length homogeneous collection, limited to N values

constructor(elementType: ElementType, limit: number, opts?: ListCompositeOpts);
static named<ElementType extends CompositeType<any, CompositeView<ElementType>, CompositeViewDU<ElementType>>>(elementType: ElementType, limit: number, opts: Require<ListCompositeOpts, "typeName">): ListCompositeType<ElementType>;
getView(tree: Tree): ListCompositeTreeView<ElementType>;

@@ -36,0 +38,0 @@ getViewDU(node: Node, cache?: unknown): ListCompositeTreeViewDU<ElementType>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const arrayBasic_1 = require("./arrayBasic");

@@ -40,2 +41,6 @@ const arrayComposite_1 = require("./arrayComposite");

}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static named(elementType, limit, opts) {
return new (named_1.namedClass(ListCompositeType, opts.typeName))(elementType, limit, opts);
}
getView(tree) {

@@ -42,0 +47,0 @@ return new listComposite_1.ListCompositeTreeView(this, tree);

import { LeafNode, Node } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ByteViews } from "./abstract";
import { BasicType } from "./basic";
export declare type UintNumberTypeOpts = {
export interface UintNumberOpts {
/** Represent the value 2^64-1 as the symbolic value `+Infinity`. @see UintNumberType for a justification. */

@@ -9,3 +10,4 @@ clipInfinity?: boolean;

setBitwiseOR?: boolean;
};
typeName?: string;
}
export declare type UintNumberByteLen = 1 | 2 | 4 | 8;

@@ -38,3 +40,4 @@ export declare type UintBigintByteLen = 1 | 2 | 4 | 8 | 16 | 32;

private readonly setBitwiseOR;
constructor(byteLength: UintNumberByteLen, opts?: UintNumberTypeOpts);
constructor(byteLength: UintNumberByteLen, opts?: UintNumberOpts);
static named(byteLength: UintNumberByteLen, opts: Require<UintNumberOpts, "typeName">): UintNumberType;
defaultValue(): number;

@@ -52,2 +55,5 @@ value_serializeToBytes({ dataView }: ByteViews, offset: number, value: number): number;

}
export interface UintBigintOpts {
typeName?: string;
}
/**

@@ -72,3 +78,4 @@ * Uint: N-bit unsigned integer (where N in [8, 16, 32, 64, 128, 256])

readonly maxSize: number;
constructor(byteLength: UintBigintByteLen);
constructor(byteLength: UintBigintByteLen, opts?: UintBigintOpts);
static named(byteLength: UintNumberByteLen, opts: Require<UintBigintOpts, "typeName">): UintBigintType;
defaultValue(): bigint;

@@ -75,0 +82,0 @@ value_serializeToBytes({ dataView }: ByteViews, offset: number, value: bigint): number;

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

const persistent_merkle_tree_1 = require("@chainsafe/persistent-merkle-tree");
const named_1 = require("../util/named");
const basic_1 = require("./basic");

@@ -40,3 +41,3 @@ /* eslint-disable @typescript-eslint/member-ordering */

}
this.typeName = `uint${byteLength * 8}`;
this.typeName = opts?.typeName ?? `uint${byteLength * 8}`;
if (opts?.clipInfinity)

@@ -54,2 +55,5 @@ this.typeName += "Inf";

}
static named(byteLength, opts) {
return new (named_1.namedClass(UintNumberType, opts.typeName))(byteLength, opts);
}
defaultValue() {

@@ -198,3 +202,3 @@ return 0;

class UintBigintType extends basic_1.BasicType {
constructor(byteLength) {
constructor(byteLength, opts) {
super();

@@ -208,3 +212,3 @@ this.byteLength = byteLength;

}
this.typeName = `uintBigint${byteLength * 8}`;
this.typeName = opts?.typeName ?? `uintBigint${byteLength * 8}`;
this.byteLength = byteLength;

@@ -216,2 +220,5 @@ this.itemsPerChunk = 32 / this.byteLength;

}
static named(byteLength, opts) {
return new (named_1.namedClass(UintBigintType, opts.typeName))(byteLength, opts);
}
defaultValue() {

@@ -218,0 +225,0 @@ return BigInt(0);

import { Node, Tree } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { Type, ByteViews } from "./abstract";

@@ -9,2 +10,5 @@ import { CompositeType } from "./composite";

declare type ValueOfTypes<Types extends Type<unknown>[]> = Types extends Type<infer T>[] ? Union<T> : never;
export declare type UnionOpts = {
typeName?: string;
};
/**

@@ -25,3 +29,4 @@ * Union: union type containing one of the given subtypes

protected readonly maxSelector: number;
constructor(types: Types);
constructor(types: Types, opts?: UnionOpts);
static named<Types extends Type<unknown>[]>(types: Types, opts: Require<UnionOpts, "typeName">): UnionType<Types>;
defaultValue(): ValueOfTypes<Types>;

@@ -28,0 +33,0 @@ getView(tree: Tree): ValueOfTypes<Types>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const composite_1 = require("./composite");

@@ -17,3 +18,3 @@ const arrayBasic_1 = require("./arrayBasic");

class UnionType extends composite_1.CompositeType {
constructor(types) {
constructor(types, opts) {
super();

@@ -40,3 +41,3 @@ this.types = types;

}
this.typeName = `Union[${types.map((t) => t.typeName).join(",")}]`;
this.typeName = opts?.typeName ?? `Union[${types.map((t) => t.typeName).join(",")}]`;
const minLens = [];

@@ -52,2 +53,5 @@ const maxLens = [];

}
static named(types, opts) {
return new (named_1.namedClass(UnionType, opts.typeName))(types, opts);
}
defaultValue() {

@@ -54,0 +58,0 @@ return {

import { Node, Tree } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ValueOf, ByteViews } from "./abstract";

@@ -32,2 +33,3 @@ import { BasicType } from "./basic";

constructor(elementType: ElementType, length: number, opts?: VectorBasicOpts);
static named<ElementType extends BasicType<unknown>>(elementType: ElementType, limit: number, opts: Require<VectorBasicOpts, "typeName">): VectorBasicType<ElementType>;
getView(tree: Tree): ArrayBasicTreeView<ElementType>;

@@ -34,0 +36,0 @@ getViewDU(node: Node, cache?: unknown): ArrayBasicTreeViewDU<ElementType>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const arrayBasic_1 = require("./arrayBasic");

@@ -39,2 +40,5 @@ const arrayBasic_2 = require("../view/arrayBasic");

}
static named(elementType, limit, opts) {
return new (named_1.namedClass(VectorBasicType, opts.typeName))(elementType, limit, opts);
}
getView(tree) {

@@ -41,0 +45,0 @@ return new arrayBasic_2.ArrayBasicTreeView(this, tree);

import { Node, Tree } from "@chainsafe/persistent-merkle-tree";
import { Require } from "../util/types";
import { ValueOf, ByteViews } from "./abstract";

@@ -32,2 +33,3 @@ import { CompositeType, CompositeView, CompositeViewDU } from "./composite";

constructor(elementType: ElementType, length: number, opts?: VectorCompositeOpts);
static named<ElementType extends CompositeType<any, CompositeView<ElementType>, CompositeViewDU<ElementType>>>(elementType: ElementType, limit: number, opts: Require<VectorCompositeOpts, "typeName">): VectorCompositeType<ElementType>;
getView(tree: Tree): ArrayCompositeTreeView<ElementType>;

@@ -34,0 +36,0 @@ getViewDU(node: Node, cache?: unknown): ArrayCompositeTreeViewDU<ElementType>;

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

const merkleize_1 = require("../util/merkleize");
const named_1 = require("../util/named");
const arrayComposite_1 = require("./arrayComposite");

@@ -38,2 +39,6 @@ const arrayComposite_2 = require("../view/arrayComposite");

}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static named(elementType, limit, opts) {
return new (named_1.namedClass(VectorCompositeType, opts.typeName))(elementType, limit, opts);
}
getView(tree) {

@@ -40,0 +45,0 @@ return new arrayComposite_2.ArrayCompositeTreeView(this, tree);

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

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

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

],
"gitHead": "2199073977689e7949428561a1df970812ac668b"
"gitHead": "2f2d12702d7ffffb43c0179dbc3ef2cf5b9b540a"
}

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