add fetchTreeFromUrl in utils.ts

This commit is contained in:
turnoffthiscomputer
2024-10-16 11:38:42 -07:00
parent 6a333f8a3e
commit 2dce3f3923

View File

@@ -87,4 +87,17 @@ export function generateCommitment(secret: string, attestation_id: string, pubke
dg2Hash2
]);
return commitment;
}
}
export async function fetchTreeFromUrl(url: string): Promise<LeanIMT> {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const commitmentMerkleTree = await response.json();
console.log("\x1b[90m%s\x1b[0m", "commitment merkle tree: ", commitmentMerkleTree);
const tree = new LeanIMT((a, b) => poseidon2([a, b]));
tree.import(commitmentMerkleTree);
return tree;
}