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

@chainsafe/persistent-merkle-tree

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/persistent-merkle-tree - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

lib/proof/index.d.ts

6

CHANGELOG.md

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

## 0.2.3 (2021-02-13)
## Features
* Add tree-offset multiproof code ([a35181](https://github.com/chainsafe/persistent-merkle-tree/commit/a35181))
## 0.2.2 (2021-02-11)

@@ -2,0 +8,0 @@

3

lib/gindex.d.ts

@@ -22,1 +22,4 @@ export declare type Gindex = bigint;

export declare function concatGindices(gindices: Gindex[]): Gindex;
export declare function gindexSibling(gindex: Gindex): Gindex;
export declare function gindexParent(gindex: Gindex): Gindex;
export declare function gindexChild(gindex: Gindex, rightChild: boolean): Gindex;

@@ -105,1 +105,13 @@ "use strict";

exports.concatGindices = concatGindices;
function gindexSibling(gindex) {
return gindex ^ BigInt(1);
}
exports.gindexSibling = gindexSibling;
function gindexParent(gindex) {
return gindex / BigInt(2);
}
exports.gindexParent = gindexParent;
function gindexChild(gindex, rightChild) {
return gindex * BigInt(2) + BigInt(rightChild);
}
exports.gindexChild = gindexChild;

@@ -7,1 +7,2 @@ export * from "./gindex";

export * from "./tree";
export * from "./proof";

@@ -12,1 +12,2 @@ "use strict";

__export(require("./tree"));
__export(require("./proof"));
import { Gindex } from "./gindex";
import { Node, Link } from "./node";
import { Proof, ProofInput } from "./proof";
export declare type Hook = (v: Tree) => void;

@@ -27,2 +28,4 @@ export declare class Tree {

iterateNodesAtDepth(depth: number, startIndex: number, count: number): IterableIterator<Node>;
getProof(input: ProofInput): Proof;
static createFromProof(proof: Proof): Tree;
}

26

lib/tree.js

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

const node_1 = require("./node");
const proof_1 = require("./proof");
const single_1 = require("./proof/single");
const zeroNode_1 = require("./zeroNode");

@@ -94,19 +96,3 @@ const ERR_INVALID_TREE = "Invalid tree operation";

getSingleProof(index) {
const proof = [];
let node = this.rootNode;
for (const i of gindex_1.gindexIterator(index)) {
if (i) {
if (node.isLeaf())
throw new Error(ERR_INVALID_TREE);
proof.push(node.left.root);
node = node.right;
}
else {
if (node.isLeaf())
throw new Error(ERR_INVALID_TREE);
proof.push(node.right.root);
node = node.left;
}
}
return proof.reverse();
return single_1.createSingleProof(this.rootNode, index)[1];
}

@@ -189,3 +175,9 @@ /**

}
getProof(input) {
return proof_1.createProof(this.rootNode, input);
}
static createFromProof(proof) {
return new Tree(proof_1.createNodeFromProof(proof));
}
}
exports.Tree = Tree;
{
"name": "@chainsafe/persistent-merkle-tree",
"version": "0.2.2",
"version": "0.2.3",
"description": "Merkle tree implemented as a persistent datastructure",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -70,2 +70,27 @@ # Persistent Merkle Tree

// Multiple types of proofs are supported through the `getProof` interface
// For example, a multiproof for multiple gindices can be generated like so
import {ProofType} from "@chainsafe/persistent-merkle-tree";
const gindices: BigInt[] = [...];
const proof: Proof = tree.getProof({
type: ProofType.treeOffset,
gindices,
});
// `Proof` objects can be used to recreate `Tree` objects
// These `Tree` objects can be navigated as usual for all nodes contained in the proof
// Navigating to unknown/unproven nodes results in an error
const partialTree: Tree = Tree.createFromProof(proof);
const unknownGindex: BigInt = ...;
gindices.includes(unknownGindex) // false
partialTree.getRoot(unknownGindex) // throws
```

@@ -72,0 +97,0 @@

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