Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const elements = rawActions.map((action) => {
return getActionHash(action)
})
// Pad the list of elements out with default hashes if len < a power of 2.
const filledElements = []
for (let i = 0; i < Math.pow(2, Math.ceil(Math.log2(elements.length))); i++) {
if (i < elements.length) {
filledElements.push(elements[i])
} else {
filledElements.push(ethers.utils.keccak256(ethers.constants.HashZero))
}
}
// merkletreejs expects things to be buffers.
const tree = new MerkleTree(
filledElements.map((element) => {
return fromHexString(element)
}),
(el: Buffer | string): Buffer => {
return fromHexString(ethers.utils.keccak256(el))
}
)
return {
root: toHexString(tree.getRoot()),
actions: rawActions.map((action, idx) => {
return {
action,
proof: {
actionIndex: idx,
siblings: tree.getProof(getActionHash(action), idx).map((element) => {
})
const filledElements = []
for (let i = 0; i < Math.pow(2, Math.ceil(Math.log2(elements.length))); i++) {
if (i < elements.length) {
filledElements.push(elements[i])
} else {
filledElements.push(ethers.utils.keccak256(ethers.constants.HashZero))
}
}
const bufs = filledElements.map((element) => {
return fromHexString(element)
})
const tree = new MerkleTree(
bufs,
(el: Buffer | string): Buffer => {
return fromHexString(ethers.utils.keccak256(el))
}
)
return {
root: toHexString(tree.getRoot()),
actions: rawActions.map((action, idx) => {
return {
action: action,
proof: {
actionIndex: idx,
siblings: tree.getProof(getLeafHash(action), idx).map((element) => {
return element.data
}),