I am attempting to verify a Merkle Tree using the metaplex SDK for the Candy Guard from Cm v3. Specifically I wanna get this working in JS, same as this in Rust What I have is this:
import {
getMerkleProof,
getMerkleRoot,
getMerkleTree,
} from "@metaplex-foundation/js";
import { keccak_256 } from "@noble/hashes/sha3";
const allowList = [
"AT8nPwujHAD14cLojTcB1qdBzA1VXnT6LVGuUd6Y73Cy",
"AT8nPwujHAD14cLojsTcB1zzqdBzA1VXnTtLVGuUd6Y73Cy",
"Ur1CbWSGsXCdedknRbJsEk7urwAvu1uddmQv51nAnXB",
"GjwcWFQYzemBtpUoN5fMAP2FZviTtMRWCmrppGuTthJS",
];
// what is stored on chain
const merkleRoot = getMerkleRoot(allowList);
console.log({ merkleRoot: merkleRoot });
// what is passed via router guard along with payer
const validMerkleProof = getMerkleProof(
allowList,
"Ur1CbWSGsXCdedknRbJsEk7urwAvu1uddmQv51nAnXB"
);
const isTreeValid = getMerkleTree(allowList).verify(
validMerkleProof.map((e) => Buffer.from(keccak_256(e))),
Buffer.from(keccak_256("Ur1CbWSGsXCdedknRbJsEk7urwAvu1uddmQv51nAnXB")),
Buffer.from(keccak_256(merkleRoot.toString()))
);
console.log({ tree1: isTreeValid });
I'd like to get isTreeValid to be true, I cant figure out how to bufferize, hash the data I pass into the verify function.
I am just doing this to inspect stuff, no real purpose beyond exploring.