{"version":3,"file":"merkle.cjs","sources":["../../../src/utils/merkle.ts"],"sourcesContent":["import { MerkleTree } from 'merkletreejs';\nimport { keccak_256 } from '@noble/hashes/sha3';\n\n/**\n * Describes the required data input for\n * handling Merkle Tree operations.\n */\ntype MerkleTreeInput = Uint8Array | string;\n\n/**\n * Creates a Merkle Tree from the provided data.\n */\nexport const getMerkleTree = (data: MerkleTreeInput[]): MerkleTree => {\n  return new MerkleTree(data.map(keccak_256), keccak_256, {\n    sortPairs: true,\n  });\n};\n\n/**\n * Creates a Merkle Root from the provided data.\n *\n * This root provides a short identifier for the\n * provided data that is unique and deterministic.\n * This means, we can use this root to verify that\n * a given data is part of the original data set.\n */\nexport const getMerkleRoot = (data: MerkleTreeInput[]): Uint8Array => {\n  return getMerkleTree(data).getRoot();\n};\n\n/**\n * Creates a Merkle Proof for a given data item.\n *\n * This proof can be used to verify that the given\n * data item is part of the original data set.\n */\nexport const getMerkleProof = (\n  data: MerkleTreeInput[],\n  leaf: MerkleTreeInput,\n  index?: number\n): Uint8Array[] => {\n  return getMerkleTree(data)\n    .getProof(Buffer.from(keccak_256(leaf)), index)\n    .map((proofItem) => proofItem.data);\n};\n\n/**\n * Creates a Merkle Proof for a data item at a given index.\n *\n * This proof can be used to verify that the data item at\n * the given index is part of the original data set.\n */\nexport const getMerkleProofAtIndex = (\n  data: MerkleTreeInput[],\n  index: number\n): Uint8Array[] => {\n  return getMerkleProof(data, data[index], index);\n};\n"],"names":["getMerkleTree","data","MerkleTree","map","keccak_256","sortPairs","getMerkleRoot","getRoot","getMerkleProof","leaf","index","getProof","Buffer","from","proofItem","getMerkleProofAtIndex"],"mappings":";;;;;;;AAGA;AACA;AACA;AACA;;AAGA;AACA;AACA;IACaA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,IAAuB,EAAiB;EACpE,OAAO,IAAIC,uBAAU,CAACD,IAAI,CAACE,GAAG,CAACC,eAAU,CAAC,EAAEA,eAAU,EAAE;AACtDC,IAAAA,SAAS,EAAE,IAAA;AACb,GAAC,CAAC,CAAA;AACJ,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IACaC,aAAa,GAAG,SAAhBA,aAAaA,CAAIL,IAAuB,EAAiB;AACpE,EAAA,OAAOD,aAAa,CAACC,IAAI,CAAC,CAACM,OAAO,EAAE,CAAA;AACtC,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACzBP,IAAuB,EACvBQ,IAAqB,EACrBC,KAAc,EACG;EACjB,OAAOV,aAAa,CAACC,IAAI,CAAC,CACvBU,QAAQ,CAACC,MAAM,CAACC,IAAI,CAACT,eAAU,CAACK,IAAI,CAAC,CAAC,EAAEC,KAAK,CAAC,CAC9CP,GAAG,CAAC,UAACW,SAAS,EAAA;IAAA,OAAKA,SAAS,CAACb,IAAI,CAAA;GAAC,CAAA,CAAA;AACvC,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACO,IAAMc,qBAAqB,GAAG,SAAxBA,qBAAqBA,CAChCd,IAAuB,EACvBS,KAAa,EACI;EACjB,OAAOF,cAAc,CAACP,IAAI,EAAEA,IAAI,CAACS,KAAK,CAAC,EAAEA,KAAK,CAAC,CAAA;AACjD;;;;;;;"}