rooch icon indicating copy to clipboard operation
rooch copied to clipboard

Add amount_limit field to VerificationMethod for spending control in DID documents

Open Copilot opened this issue 8 months ago • 1 comments

This PR adds an amount_limit field to the VerificationMethod struct in the DID system, enabling fine-grained spending control for different verification methods within a DID document.

Changes Made

Core Data Structure

  • Added amount_limit: u256 field to VerificationMethod struct in both Move and Rust code
  • Updated struct serialization/deserialization logic to handle the new field

API Updates

All DID creation and verification method management functions now require amount limit parameters:

// Before
did::add_verification_method_entry(
    &signer, fragment, method_type, public_key, relationships
);

// After  
did::add_verification_method_entry(
    &signer, fragment, method_type, public_key, 1000000u256, relationships
);

Updated Functions

  • create_did_object_for_self_entry() - now accepts user_vm_amount_limit
  • create_did_object_via_cadop_with_did_key_entry() - now accepts both user and service amount limits
  • add_verification_method_entry() - now accepts amount_limit parameter
  • All internal creation and authentication helper functions

Test Coverage

  • Updated all test files with appropriate amount limits (500K-10M range)
  • Primary account keys: 10M tokens (higher limit for main keys)
  • Secondary verification methods: 1M-2M tokens
  • Specialized keys (ECDSA-R1): 1.5M tokens

Documentation

  • Updated did_guide.md to reflect the new VerificationMethod structure
  • Added clear documentation about the purpose and usage of amount limits

Benefits

This change enables:

  1. Graduated security policies - Different keys can have different spending limits
  2. Risk management - Limit exposure if secondary keys are compromised
  3. Multi-tier access control - Beyond permission types, now amount-based restrictions
  4. Flexible key management - Primary keys for large amounts, secondary keys for smaller transactions

Breaking Change

This is intentionally a breaking change to force developers to explicitly consider spending limits when creating verification methods, improving overall security posture.

Example Usage

// Create DID with 10M limit for primary account key
did::create_did_object_for_self_entry(&signer, public_key, 10000000u256);

// Add secondary verification method with 1M limit
did::add_verification_method_entry(
    &signer, 
    string::utf8(b"backup-key"), 
    string::utf8(b"Ed25519VerificationKey2020"),
    backup_public_key,
    1000000u256,  // 1M token limit
    vector[1u8]   // assertion_method
);

Fixes #3643.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jul 06 '25 11:07 Copilot

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rooch-portal-v2.1 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2025 0:43am
test-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 6, 2025 0:43am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
rooch ⬜️ Ignored (Inspect) Visit Preview Jul 6, 2025 0:43am

vercel[bot] avatar Jul 06 '25 11:07 vercel[bot]