Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8e5575
feat(context-config): implement context groups and migration support
rtb-12 Feb 18, 2026
995d3d2
feat(context-config): implement group management functionality
rtb-12 Feb 18, 2026
5e4cb25
feat(context-config): enhance context-group management with registrat…
rtb-12 Feb 19, 2026
1ece103
feat(context-config): implement target application management for con…
rtb-12 Feb 19, 2026
65b473d
feat(context-proxy): add proxy methods for group registration and unr…
rtb-12 Feb 19, 2026
4209eda
fix(Cargo.toml): update calimero-context-config dependency to use git…
rtb-12 Feb 19, 2026
a4d4f42
refactor(context-config): streamline code formatting and improve read…
rtb-12 Feb 19, 2026
fa8852e
refactor(context-config): improve function signatures and test assert…
rtb-12 Feb 19, 2026
20645f6
feat(context-config): enhance group management with nonce tracking an…
rtb-12 Feb 19, 2026
c00f21a
feat(context-config): add context registration approval functionality
rtb-12 Feb 19, 2026
a720981
feat(context-config): add context IDs tracking for group management
rtb-12 Feb 19, 2026
169bee6
refactor(context-config): clear group data during context reset
rtb-12 Feb 19, 2026
807a9e8
feat(context-proxy): update proxy_unregister_from_group to include gr…
rtb-12 Feb 19, 2026
308a927
feat(context-config): add fetch_group_nonce query method
rtb-12 Mar 4, 2026
a01fb00
feat(context-config): add group invitation commit/reveal contract logic
rtb-12 Mar 5, 2026
ec1e014
feat(context-config): add group_members view and join-context-via-group
rtb-12 Mar 5, 2026
d067199
feat(context-config): cascade group member removal to contexts
rtb-12 Mar 6, 2026
521f98d
fix(groups): propagate migration method on-chain for lazy upgrade peers
rtb-12 Mar 6, 2026
b1a9240
feat(context-config): add group permission system with capabilities a…
rtb-12 Mar 9, 2026
a93be63
test(context-config): add contract integration tests for group permis…
rtb-12 Mar 9, 2026
5833948
fix(context-config): address three BugBot issues in group management
rtb-12 Mar 17, 2026
370394b
fix(context-config): clean up visibility/allowlist on unregister and …
rtb-12 Mar 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ tokio = "1.35.1"

calimero-context-config-near = { path = "./contracts/near/context-config" }

[patch."https://github.com/calimero-network/core"]
calimero-context-config = { path = "../core/crates/context/config" }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local filesystem path patch committed in Cargo.toml

High Severity

The [patch] section overrides calimero-context-config with a local filesystem path (../core/crates/context/config). This breaks builds for anyone who doesn't have the core repo checked out at that exact relative path, including CI pipelines. The corresponding Cargo.lock also lost its git source line, confirming the override is active.

Fix in Cursor Fix in Web


[profile.release]
strip = "symbols"
lto = "fat"
Expand Down
4 changes: 4 additions & 0 deletions contracts/near/context-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ migrations = []
## migrations (mutually exclusive) ##
01_guard_revisions = []
02_nonces = []
03_context_groups = []
04_group_invitations = []
05_group_migration_method = []
06_group_permissions = []
## migrations (mutually exclusive) ##
187 changes: 187 additions & 0 deletions contracts/near/context-config/src/group_invitation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
use calimero_context_config::repr::{Repr, ReprBytes};
use calimero_context_config::types::{ContextGroupId, SignedGroupRevealPayload};
use near_sdk::borsh;
use near_sdk::{env, require, BlockHeight, CryptoHash};

use super::ContextConfigs;

pub type Ed25519Signature = [u8; 64];

impl ContextConfigs {
/// ### Step 1: Commit Group Invitation
///
/// Anonymously commits to a hash of a future reveal payload.
/// Prevents MEV attacks. Can be called by the joiner or a relayer.
///
/// # Arguments
///
/// * `group_id` - The group for which the commitment is being made.
/// * `commitment_hash` - A hex-encoded SHA-256 hash of the `GroupRevealPayloadData`.
/// * `expiration_block_height` - The block height at which the commitment expires.
pub fn commit_group_invitation(
&mut self,
group_id: Repr<ContextGroupId>,
commitment_hash: String,
expiration_block_height: BlockHeight,
) {
let group = self
.groups
.get_mut(&group_id)
.expect("Group does not exist");

let hash_bytes: CryptoHash = hex::decode(&commitment_hash)
.expect("Invalid hex hash")
.try_into()
.expect("Hash must be 32 bytes");

require!(
!group.invitation_commitments.contains_key(&hash_bytes),
"This commitment has already been made"
);

let current_block_height: BlockHeight = env::block_height();
require!(
current_block_height < expiration_block_height,
"This invitation is already expired"
);

let _ignored = group
.invitation_commitments
.insert(hash_bytes, expiration_block_height);

env::log_str(&format!(
"Successfully committed the group invitation image {} in group {}",
commitment_hash, group_id
));
}

/// ### Step 2: Reveal Group Invitation
///
/// Submits the full payload to claim the group invitation. The contract verifies
/// this payload against the prior commitment and validates all signatures and permissions.
///
/// # Arguments
///
/// * `payload` - A `SignedGroupRevealPayload` containing the original data and the
/// joiner's signature.
pub fn reveal_group_invitation(&mut self, payload: SignedGroupRevealPayload) {
let payload_data = payload.data;
let invitation = payload_data.signed_open_invitation.invitation.clone();
let group_id = invitation.group_id;

require!(
invitation.protocol == "near",
"The invitation was designated for another protocol"
);
require!(
invitation.contract_id == env::current_account_id(),
"The invitation was designated for another contract"
);

let group = self
.groups
.get_mut(&group_id)
.expect("Group does not exist");

// 1. Hash the revealed data to find the original commitment.
let payload_data_bytes =
borsh::to_vec(&payload_data).expect("Failed to serialize payload data");
let payload_data_hash_vec = env::sha256(&payload_data_bytes);
let payload_data_hash: CryptoHash = payload_data_hash_vec
.clone()
.try_into()
.expect("infallible conversion");

// 2. Remove the commitment (replay prevention).
let _ignored = group
.invitation_commitments
.remove(&payload_data_hash)
.expect(
"No matching commitment found. It may have expired, been invalid, or already used",
);

// 3. Check expiration.
require!(
env::block_height() <= invitation.expiration_height,
"The invitation has expired."
);

// 4. Check the new member is not already in the group.
require!(
!group.members.contains(&payload_data.new_member_identity),
"Member already in group"
);
require!(
!group.admins.contains(&payload_data.new_member_identity),
"Member is already a group admin"
);

// 5. Verify the joiner's signature over the payload data.
let new_member_signature_bytes: Ed25519Signature = hex::decode(&payload.invitee_signature)
.expect("Invalid hex signature for new member")
.try_into()
.expect("Invalid signature length");
require!(
env::ed25519_verify(
&new_member_signature_bytes,
&payload_data_hash_vec,
&payload_data.new_member_identity.as_bytes()
),
"New member's signature is invalid."
);

// 6. Verify the inviter's signature over the invitation.
let inviter_identity = invitation.inviter_identity;
let inviter_signature_bytes: Ed25519Signature =
hex::decode(&payload_data.signed_open_invitation.inviter_signature)
.expect("Invalid hex inviter signature")
.try_into()
.expect("Invalid signature length");

let invitation_bytes = borsh::to_vec(&invitation).expect("Failed to serialize invitation");
require!(
env::ed25519_verify(
&inviter_signature_bytes,
&env::sha256(&invitation_bytes),
&inviter_identity.as_bytes()
),
"Inviter's signature is invalid"
);

// 7. Verify the inviter is a group admin or has CAN_INVITE_MEMBERS capability.
let is_admin = group.admins.contains(&inviter_identity);
let can_invite = is_admin
|| group
.member_capabilities
.get(&inviter_identity)
.map_or(false, |caps| {
caps & crate::MemberCapabilities::CAN_INVITE_MEMBERS != 0
});
require!(
can_invite,
"Inviter lacks permission to invite members"
);

// 8. Prevent replay of the inviter's signature.
let inviter_signature_hash: CryptoHash = env::sha256(&inviter_signature_bytes)
.try_into()
.expect("infallible conversion");
require!(
group.used_invitations.insert(inviter_signature_hash),
"This invitation has already been used in this group."
);

// 9. Add the new member to the group with default capabilities.
let _ignored = group.members.insert(payload_data.new_member_identity);
let _ignored = group.member_capabilities.insert(
payload_data.new_member_identity,
group.default_member_capabilities,
);

env::log_str(&format!(
"Account {} successfully joined group {}",
Repr::new(payload_data.new_member_identity),
Repr::new(group_id)
));
}
}
13 changes: 13 additions & 0 deletions contracts/near/context-config/src/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ impl<T> Guard<T> {
Ok(GuardHandle { inner: self })
}

/// Direct mutable access for internally-authorized operations.
///
/// Use this for group-authorized context mutations where the caller
/// has already verified authorization at a higher level (e.g., group
/// admin check). The revision counter is incremented to maintain
/// sync consistency, same as `GuardMut::drop`.
///
/// The caller MUST verify authorization before calling this.
pub fn authorized_get_mut(&mut self) -> &mut T {
self.revision = self.revision.wrapping_add(1);
&mut self.inner
}

pub fn into_inner(self) -> T {
let mut this = self;
this.priviledged.clear();
Expand Down
Loading
Loading