|
|
@ -5,10 +5,10 @@ class MerkleTree { |
|
|
|
// Filter empty strings and hash elements
|
|
|
|
// Filter empty strings and hash elements
|
|
|
|
this.elements = elements.filter(el => el).map(el => keccak256(el)); |
|
|
|
this.elements = elements.filter(el => el).map(el => keccak256(el)); |
|
|
|
|
|
|
|
|
|
|
|
// Deduplicate elements
|
|
|
|
|
|
|
|
this.elements = this.bufDedup(this.elements); |
|
|
|
|
|
|
|
// Sort elements
|
|
|
|
// Sort elements
|
|
|
|
this.elements.sort(Buffer.compare); |
|
|
|
this.elements.sort(Buffer.compare); |
|
|
|
|
|
|
|
// Deduplicate elements
|
|
|
|
|
|
|
|
this.elements = this.bufDedup(this.elements); |
|
|
|
|
|
|
|
|
|
|
|
// Create layers
|
|
|
|
// Create layers
|
|
|
|
this.layers = this.getLayers(this.elements); |
|
|
|
this.layers = this.getLayers(this.elements); |
|
|
@ -113,7 +113,7 @@ class MerkleTree { |
|
|
|
|
|
|
|
|
|
|
|
bufDedup (elements) { |
|
|
|
bufDedup (elements) { |
|
|
|
return elements.filter((el, idx) => { |
|
|
|
return elements.filter((el, idx) => { |
|
|
|
return this.bufIndexOf(el, elements) === idx; |
|
|
|
return idx === 0 || !elements[idx - 1].equals(el); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|