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

merkletreejs

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merkletreejs - npm Package Compare versions

Comparing version 0.0.19 to 0.0.20

46

index.js

@@ -42,2 +42,3 @@ const reverse = require('buffer-reverse')

// TODO: documentation
createHashes(nodes) {

@@ -259,10 +260,5 @@ while (nodes.length > 1) {

static bufferify(x) {
return bufferify(x)
}
static print(tree, opts) {
opts = opts || {}
const log = opts instanceof Object && opts.log !== false
const layers = tree.getLayers().map(x => x.map(x => x.toString('hex')))
// TODO: documentation
getLayersAsObject() {
const layers = this.getLayers().map(x => x.map(x => x.toString('hex')))
const objs = []

@@ -272,4 +268,5 @@ for (let i = 0; i < layers.length; i++) {

for (let j = 0; j < layers[i].length; j++) {
const obj = { [layers[i][j]]: {} }
const obj = { [layers[i][j]]: null }
if (objs.length) {
obj[layers[i][j]] = {}
const a = objs.shift()

@@ -291,7 +288,30 @@ const akey = Object.keys(a)[0]

const str = treeify.asTree(objs[0], true)
if (log) console.log(str)
return objs[0]
}
return str
// TODO: documentation
print() {
MerkleTree.print(this)
}
// TODO: documentation
toTreeString() {
const obj = this.getLayersAsObject()
return treeify.asTree(obj, true)
}
// TODO: documentation
toString() {
return this.toTreeString()
}
// TODO: documentation
static bufferify(x) {
return bufferify(x)
}
// TODO: documentation
static print(tree) {
console.log(tree.toString())
}
}

@@ -326,3 +346,3 @@

function isHexStr(v, size) {
function isHexStr(v) {
return (typeof v === 'string' && /^(0x)?[0-9A-Fa-f]*$/.test(v))

@@ -329,0 +349,0 @@ }

{
"name": "merkletreejs",
"version": "0.0.19",
"version": "0.0.20",
"description": "Construct Merkle Trees and verify proofs",

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

@@ -313,2 +313,21 @@ const test = require('tape')

test('getLayersAsObject', t => {
t.plan(1)
const leaves = ['a', 'b', 'c'].map(x => sha3(x))
const tree = new MerkleTree(leaves, sha256)
const obj = tree.getLayersAsObject()
t.deepEqual(obj, {
'311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae': {
'0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2': {
'0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2': null
},
'176f0f307632fdd5831875eb709e2f68d770b102262998b214ddeb3f04164ae1': {
'3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb': null,
'b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510': null
}
}
})
})
test('print', t => {

@@ -319,5 +338,4 @@ t.plan(1)

const tree = new MerkleTree(leaves, sha256)
const str = MerkleTree.print(tree, {log: false})
t.equal(str,
t.equal(tree.toString(),
`└─ 311d2e46f49b15fff8b746b74ad57f2cc9e0d9939fda94387141a2d3fdf187ae

@@ -324,0 +342,0 @@ ├─ 176f0f307632fdd5831875eb709e2f68d770b102262998b214ddeb3f04164ae1

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