Skip to content

Commit c032474

Browse files
feat: add wasm bindings for Drive verification functions
1 parent 399d2d7 commit c032474

File tree

78 files changed

+11857
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+11857
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ node_modules
3434
# Rust build artifacts
3535
/target
3636
.gitaipconfig
37+
38+
# wasm-drive-verify build artifacts
39+
packages/wasm-drive-verify/target/
40+
packages/wasm-drive-verify/wasm/

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ members = [
3030
"packages/check-features",
3131
"packages/wallet-utils-contract",
3232
"packages/token-history-contract",
33-
"packages/keyword-search-contract"
33+
"packages/keyword-search-contract",
34+
"packages/wasm-drive-verify"
3435
]
3536

3637
exclude = ["packages/wasm-sdk"] # This one is experimental and not ready for use

packages/rs-drive/src/verify/system/mod.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,74 @@ mod verify_epoch_proposers;
44
mod verify_total_credits_in_system;
55
mod verify_upgrade_state;
66
mod verify_upgrade_vote_status;
7+
8+
// Re-export verify functions as standalone functions
9+
pub use crate::drive::Drive;
10+
use crate::error::Error;
11+
use crate::verify::RootHash;
12+
use dpp::block::epoch::EpochIndex;
13+
use dpp::block::extended_epoch_info::ExtendedEpochInfo;
14+
use dpp::fee::Credits;
15+
use dpp::prelude::CoreBlockHeight;
16+
use dpp::util::deserializer::ProtocolVersion;
17+
use dpp::version::PlatformVersion;
18+
use grovedb::Element;
19+
use nohash_hasher::IntMap;
20+
use std::collections::BTreeMap;
21+
22+
/// Wrapper for Drive::verify_elements
23+
pub fn verify_elements(
24+
proof: &[u8],
25+
path: Vec<Vec<u8>>,
26+
keys: Vec<Vec<u8>>,
27+
platform_version: &PlatformVersion,
28+
) -> Result<(RootHash, BTreeMap<Vec<u8>, Option<Element>>), Error> {
29+
Drive::verify_elements(proof, path, keys, platform_version)
30+
}
31+
32+
/// Wrapper for Drive::verify_epoch_infos
33+
pub fn verify_epoch_infos(
34+
proof: &[u8],
35+
current_epoch: EpochIndex,
36+
start_epoch: Option<EpochIndex>,
37+
count: u16,
38+
ascending: bool,
39+
platform_version: &PlatformVersion,
40+
) -> Result<(RootHash, Vec<ExtendedEpochInfo>), Error> {
41+
Drive::verify_epoch_infos(proof, current_epoch, start_epoch, count, ascending, platform_version)
42+
}
43+
44+
/// Wrapper for Drive::verify_total_credits_in_system
45+
pub fn verify_total_credits_in_system(
46+
proof: &[u8],
47+
core_subsidy_halving_interval: u32,
48+
request_activation_core_height: impl Fn() -> Result<CoreBlockHeight, Error>,
49+
current_core_height: CoreBlockHeight,
50+
platform_version: &PlatformVersion,
51+
) -> Result<(RootHash, Credits), Error> {
52+
Drive::verify_total_credits_in_system(
53+
proof,
54+
core_subsidy_halving_interval,
55+
request_activation_core_height,
56+
current_core_height,
57+
platform_version,
58+
)
59+
}
60+
61+
/// Wrapper for Drive::verify_upgrade_state
62+
pub fn verify_upgrade_state(
63+
proof: &[u8],
64+
platform_version: &PlatformVersion,
65+
) -> Result<(RootHash, IntMap<ProtocolVersion, u64>), Error> {
66+
Drive::verify_upgrade_state(proof, platform_version)
67+
}
68+
69+
/// Wrapper for Drive::verify_upgrade_vote_status
70+
pub fn verify_upgrade_vote_status(
71+
proof: &[u8],
72+
start_protx_hash: Option<[u8; 32]>,
73+
count: u16,
74+
platform_version: &PlatformVersion,
75+
) -> Result<(RootHash, BTreeMap<[u8; 32], ProtocolVersion>), Error> {
76+
Drive::verify_upgrade_vote_status(proof, start_protx_hash, count, platform_version)
77+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[target.wasm32-unknown-unknown]
2+
rustflags = ["--cfg", "getrandom_backend=\"wasm_js\""]
3+
4+
[build]
5+
target = "wasm32-unknown-unknown"

0 commit comments

Comments
 (0)