Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getPlasmaProof(leaf) {
let index = -1
for (let i = 0; i < this.leaves.length; i++) {
if (Buffer.compare(leaf, this.leaves[i]) === 0) {
index = i
}
}
const proof = []
if (index <= this.getLeaves().length) {
let siblingIndex
for (let i = 0; i < this.layers.length - 1; i++) {
if (index % 2 === 0) {
siblingIndex = index + 1
} else {
siblingIndex = index - 1
}
index = parseInt(index / 2)
proof.push(this.layers[i][siblingIndex])
}
function compareObjectIds(id1, id2) {
var a = Buffer.from(id1.toHexString(), 'hex');
var b = Buffer.from(id2.toHexString(), 'hex');
if (a === b) {
return 0;
}
if (typeof Buffer.compare === 'function') {
return Buffer.compare(a, b);
}
var x = a.length;
var y = b.length;
var len = Math.min(x, y);
for (var i = 0; i < len; i++) {
if (a[i] !== b[i]) {
break;
}
}
if (i !== len) {
x = a[i];
y = b[i];
}
getPlasmaProof(leaf) {
let index = -1
for (let i = 0; i < this.leaves.length; i++) {
if (Buffer.compare(leaf, this.leaves[i]) === 0) {
index = i
}
}
const proof = []
if (index <= this.getLeaves().length) {
let siblingIndex
for (let i = 0; i < this.layers.length - 1; i++) {
if (index % 2 === 0) {
siblingIndex = index + 1
} else {
siblingIndex = index - 1
}
index = parseInt(index / 2)
proof.push(this.layers[i][siblingIndex])
}
async validate(chain) {
const p = []
for (let i = 0; i < this.transactions.length; i++) {
const tx = this.transactions[i]
p.push(tx.validate(chain))
}
const results = await Promise.all(p)
if (!results.every(r => r)) {
return false
}
const merkleHashes = this.transactions.map(tx => tx.merkleHash())
const tree = new FixedMerkleTree(16, merkleHashes)
if (Buffer.compare(tree.getRoot(), this.header.root) !== 0) {
return false
}
return true
}
function compareObjectIds(id1, id2) {
var a = Buffer.from(id1.toHexString(), 'hex');
var b = Buffer.from(id2.toHexString(), 'hex');
if (a === b) {
return 0;
}
if (typeof Buffer.compare === 'function') {
return Buffer.compare(a, b);
}
var x = a.length;
var y = b.length;
var len = Math.min(x, y);
for (var i = 0; i < len; i++) {
if (a[i] !== b[i]) {
break;
}
}
if (i !== len) {
x = a[i];
y = b[i];
}
function compareObjectIds(id1, id2) {
var a = Buffer.from(id1.toHexString(), 'hex');
var b = Buffer.from(id2.toHexString(), 'hex');
if (a === b) {
return 0;
}
if (typeof Buffer.compare === 'function') {
return Buffer.compare(a, b);
}
var x = a.length;
var y = b.length;
var len = Math.min(x, y);
for (var i = 0; i < len; i++) {
if (a[i] !== b[i]) {
break;
}
}
if (i !== len) {
x = a[i];
y = b[i];
}
getProof(leaf, index) {
const proof = []
if (typeof index !== 'number') {
index = -1
for (let i = 0; i < this.leaves.length; i++) {
if (Buffer.compare(leaf, this.leaves[i]) === 0) {
index = i
}
}
}
if (index <= -1) {
return []
}
for (let i = 0; i < this.layers.length; i++) {
const layer = this.layers[i]
const isRightNode = index % 2
const pairIndex = isRightNode ? index - 1 : index + 1
if (pairIndex < layer.length) {
proof.push({
return false
}
let hash = value
for (let i = 0; i < proof.length; i++) {
const node = proof[i]
if (index % 2 === 0) {
hash = sha3(Buffer.concat([hash, node]))
} else {
hash = sha3(Buffer.concat([node, hash]))
}
index = parseInt(index / 2)
}
return Buffer.compare(hash, root) === 0
}
}
let hash = targetNode
if (!Array.isArray(proof) || !proof.length || !targetNode || !root) {
return false
}
for (let i = 0; i < proof.length; i++) {
const node = proof[i]
const isLeftNode = node.position === 'left'
const buffers = []
buffers.push(hash)
buffers[isLeftNode ? 'unshift' : 'push'](node.data)
hash = sha3(Buffer.concat(buffers))
}
return Buffer.compare(hash, root) === 0
}
}