Remove redundant method
This commit is contained in:
parent
e3f40d5e4f
commit
55e45e6172
|
@ -32,7 +32,6 @@ Class reprensenting a Merkle Tree
|
|||
* [bufferToHex](_src_merkletree_.merkletree.md#buffertohex)
|
||||
* [bufferify](_src_merkletree_.merkletree.md#bufferify)
|
||||
* [bufferifyFn](_src_merkletree_.merkletree.md#bufferifyfn)
|
||||
* [combineHashes](_src_merkletree_.merkletree.md#combinehashes)
|
||||
* [getDepth](_src_merkletree_.merkletree.md#getdepth)
|
||||
* [getHexLayers](_src_merkletree_.merkletree.md#gethexlayers)
|
||||
* [getHexLayersFlat](_src_merkletree_.merkletree.md#gethexlayersflat)
|
||||
|
@ -420,20 +419,6 @@ Name | Type |
|
|||
|
||||
___
|
||||
|
||||
### combineHashes
|
||||
|
||||
▸ **combineHashes**(`hashes`: Buffer[]): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`hashes` | Buffer[] |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### getDepth
|
||||
|
||||
▸ **getDepth**(): *number*
|
||||
|
|
|
@ -32,7 +32,17 @@ ___
|
|||
|
||||
### `Optional` concatenator
|
||||
|
||||
• **concatenator**? : *any*
|
||||
• **concatenator**? : *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`inputs`: Buffer[]): *Buffer | Buffer[] | BigInt[]*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`inputs` | Buffer[] |
|
||||
|
||||
___
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "merkletreejs",
|
||||
"version": "0.3.5",
|
||||
"version": "0.3.6",
|
||||
"description": "Construct Merkle Trees and verify proofs",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
|
|
@ -32,7 +32,7 @@ export interface Options {
|
|||
/** If set to `true`, the resulting tree will be a complete tree. Recommended for use of multiProofs. */
|
||||
complete?: boolean;
|
||||
|
||||
concatenator?: any
|
||||
concatenator?: (inputs: Buffer[]) => Buffer | Buffer[] | BigInt[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +176,7 @@ export class MerkleTree extends Base {
|
|||
// is bitcoin tree
|
||||
if (this.isBitcoinTree) {
|
||||
// Bitcoin method of duplicating the odd ending nodes
|
||||
hash = this.hashFn(this.combineHashes([reverse(data), reverse(data)]))
|
||||
hash = this.hashFn(this.concatenator([reverse(data), reverse(data)]))
|
||||
hash = reverse(this.hashFn(hash))
|
||||
|
||||
this.layers[layerIndex].push(hash)
|
||||
|
@ -207,7 +207,7 @@ export class MerkleTree extends Base {
|
|||
combined.sort(Buffer.compare)
|
||||
}
|
||||
|
||||
let hash = this.hashFn(this.combineHashes(combined))
|
||||
let hash = this.hashFn(this.concatenator(combined))
|
||||
|
||||
// double hash if bitcoin tree
|
||||
if (this.isBitcoinTree) {
|
||||
|
@ -1130,21 +1130,21 @@ export class MerkleTree extends Base {
|
|||
|
||||
buffers[isLeftNode ? 'unshift' : 'push'](reverse(data))
|
||||
|
||||
hash = this.hashFn(this.combineHashes(buffers))
|
||||
hash = this.hashFn(this.concatenator(buffers))
|
||||
hash = reverse(this.hashFn(hash))
|
||||
} else {
|
||||
if (this.sortPairs) {
|
||||
if (Buffer.compare(hash, data) === -1) {
|
||||
buffers.push(hash, data)
|
||||
hash = this.hashFn(this.combineHashes(buffers))
|
||||
hash = this.hashFn(this.concatenator(buffers))
|
||||
} else {
|
||||
buffers.push(data, hash)
|
||||
hash = this.hashFn(this.combineHashes(buffers))
|
||||
hash = this.hashFn(this.concatenator(buffers))
|
||||
}
|
||||
} else {
|
||||
buffers.push(hash)
|
||||
buffers[isLeftNode ? 'unshift' : 'push'](data)
|
||||
hash = this.hashFn(this.combineHashes(buffers))
|
||||
hash = this.hashFn(this.concatenator(buffers))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1203,7 +1203,7 @@ export class MerkleTree extends Base {
|
|||
pair = pair.sort(Buffer.compare)
|
||||
}
|
||||
|
||||
const hash = pair[1] ? this.hashFn(this.combineHashes(pair)) : pair[0]
|
||||
const hash = pair[1] ? this.hashFn(this.concatenator(pair)) : pair[0]
|
||||
tree[(index / 2) | 0] = hash
|
||||
indexqueue.push((index / 2) | 0)
|
||||
}
|
||||
|
@ -1231,7 +1231,7 @@ export class MerkleTree extends Base {
|
|||
const bufA: Buffer = proofFlag[i] ? (leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]) : proofs[proofPos++]
|
||||
const bufB : Buffer = leafPos < leavesLen ? leaves[leafPos++] : hashes[hashPos++]
|
||||
const buffers = [bufA, bufB].sort(Buffer.compare)
|
||||
hashes[i] = this.hashFn(this.combineHashes(buffers))
|
||||
hashes[i] = this.hashFn(this.concatenator(buffers))
|
||||
}
|
||||
|
||||
return Buffer.compare(hashes[totalHashes - 1], root) === 0
|
||||
|
@ -1442,7 +1442,7 @@ export class MerkleTree extends Base {
|
|||
const parentNodeTreeIndex = parentIndices[i]
|
||||
const bufA = currentLayer[i * 2]
|
||||
const bufB = currentLayer[i * 2 + 1]
|
||||
const hash = bufB ? this.hashFn(this.combineHashes([bufA, bufB])) : bufA
|
||||
const hash = bufB ? this.hashFn(this.concatenator([bufA, bufB])) : bufA
|
||||
parentLayer.push([parentNodeTreeIndex, hash])
|
||||
}
|
||||
|
||||
|
@ -1451,10 +1451,6 @@ export class MerkleTree extends Base {
|
|||
|
||||
return tree[tree.length - 1][0][1]
|
||||
}
|
||||
|
||||
combineHashes (hashes: Buffer[]) {
|
||||
return this.concatenator(hashes)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
|
|
Loading…
Reference in New Issue