From 59d35cc02bec5f18b9140b5929e8f81f3c07dc71 Mon Sep 17 00:00:00 2001 From: ross-weir <29697678+ross-weir@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:38:03 +1100 Subject: [PATCH 1/2] add batch prover digest method --- .../authenticated-avl-tree/src/batch_avl_prover.rs | 7 +++++++ .../tests/batch-avl-prover.test.ts | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/authenticated-avl-tree/src/batch_avl_prover.rs b/packages/authenticated-avl-tree/src/batch_avl_prover.rs index 76306d5..2eec12d 100644 --- a/packages/authenticated-avl-tree/src/batch_avl_prover.rs +++ b/packages/authenticated-avl-tree/src/batch_avl_prover.rs @@ -1,6 +1,7 @@ use crate::batch_node::AVLTree; use crate::operation::{Operation, TsOperationType}; use derive_more::{From, Into}; +use ergo_avltree_rust::authenticated_tree_ops::AuthenticatedTreeOps; use ergo_avltree_rust::batch_avl_prover::BatchAVLProver as NativeBatchAVLProver; use ergo_lib_utils::MapJsValueErrorResult; use js_sys::Uint8Array; @@ -41,4 +42,10 @@ impl BatchAVLProver { pub fn generate_proof(&mut self) -> Box<[u8]> { self.0.generate_proof().to_vec().into_boxed_slice() } + + pub fn digest(&self) -> JsValue { + self.0.digest().map_or(JsValue::UNDEFINED, |digest| { + Uint8Array::from(digest.to_vec().as_slice()).into() + }) + } } diff --git a/packages/authenticated-avl-tree/tests/batch-avl-prover.test.ts b/packages/authenticated-avl-tree/tests/batch-avl-prover.test.ts index d5678c2..c85cd17 100644 --- a/packages/authenticated-avl-tree/tests/batch-avl-prover.test.ts +++ b/packages/authenticated-avl-tree/tests/batch-avl-prover.test.ts @@ -13,6 +13,16 @@ function removeOp(key: string) { } describe("BatchAVLProver", () => { + it("should return the expected empty digest", () => { + const tree = new AVLTree(32); + const bv = new BatchAVLProver(tree, true); + const actualDigest = bytesToHex(bv.digest()); + + expect(actualDigest).toBe( + "4ec61f485b98eb87153f7c57db4f5ecd75556fddbc403b41acf8441fde8e160900" + ); + }); + it("should produce the same proofs as the native rust library", () => { const insertList = [ insertOp( From 51fa2e921ea521b8df642c43e5384312c1ab50bc Mon Sep 17 00:00:00 2001 From: ross-weir <29697678+ross-weir@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:38:56 +1100 Subject: [PATCH 2/2] add changeset --- .changeset/empty-ducks-sip.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/empty-ducks-sip.md diff --git a/.changeset/empty-ducks-sip.md b/.changeset/empty-ducks-sip.md new file mode 100644 index 0000000..7009486 --- /dev/null +++ b/.changeset/empty-ducks-sip.md @@ -0,0 +1,5 @@ +--- +"@ergoplatform/authenticated-avl-tree": patch +--- + +Add `BatchAVLProver.digest()` method