This document summarizes the implementation of identity-aware transaction limits using off-chain signed claims for the Grainlify escrow system.
The identity-aware limits feature enables regulatory compliance and risk management by:
- Accepting signed identity claims from trusted KYC providers
- Enforcing different transaction limits based on identity tiers (Unverified, Basic, Verified, Premium)
- Applying risk-based adjustments to limits based on risk scores (0-100)
- Verifying claim authenticity using Ed25519 cryptographic signatures
- Storing only tier and risk score on-chain (no personal information)
Hash: 1f3267d
Added core identity types and error codes:
IdentityTierenum (Unverified, Basic, Verified, Premium)IdentityClaimstruct for signed claimsAddressIdentitystruct for stored identity dataTierLimitsandRiskThresholdsconfiguration structures- Extended
Errorenum with identity-related errors - Updated
DataKeyenum with identity storage keys
Hash: 1d0922c
Implemented cryptographic functions:
serialize_claim()- Deterministic XDR encoding for signaturesverify_claim_signature()- Ed25519 signature verificationis_claim_expired()- Expiry timestamp checkingvalidate_claim()- Format and field validationcalculate_effective_limit()- Tier and risk-based limit calculation
Hash: 8925a89
Added administrative functions:
set_authorized_issuer()- Manage trusted claim issuersset_tier_limits()- Configure tier-based transaction limitsset_risk_thresholds()- Configure risk-based adjustments- Initialize default limits and thresholds in
init() - Emit events for issuer management actions
Hash: 7093038
Implemented core functionality:
submit_identity_claim()- Verify and store identity claimsget_address_identity()- Query identity data for addressesget_effective_limit()- Calculate effective transaction limitsis_claim_valid()- Check claim validityenforce_transaction_limit()- Internal limit enforcement- Integrated limit checks into
lock_funds()andrelease_funds() - Emit events for claim submission, rejection, and limit enforcement
Hash: deb80f2
Created Go package for off-chain claim management:
IdentityClaimandIdentityTiertypesCreateClaim()- Generate new claimsSerializeClaim()- Deterministic encoding matching on-chain formatSignClaim()- Ed25519 signingVerifyClaim()- Signature verification- Test utilities for generating test claims
Hash: 9b2bafd
Added comprehensive unit tests:
- Issuer authorization management tests
- Tier limits configuration tests
- Risk thresholds configuration tests
- Default identity query tests
- Effective limit calculation tests
- Limit enforcement tests in
lock_funds()andrelease_funds() - Tests for transactions within and exceeding limits
Hash: eb5dffb
Created comprehensive documentation:
IDENTITY_LIMITS.md- Architecture, usage guide, and troubleshootingbackend/internal/identity/README.md- Go package documentation- Configuration examples
- Integration examples for KYC providers
- Security considerations and best practices
Files:
soroban/contracts/escrow/src/identity.rs- Identity types and helper functionssoroban/contracts/escrow/src/lib.rs- Contract implementation with identity functionssoroban/contracts/escrow/src/identity_test.rs- Unit tests
Key Functions:
- Admin:
set_authorized_issuer,set_tier_limits,set_risk_thresholds - User:
submit_identity_claim,get_address_identity,get_effective_limit,is_claim_valid - Internal:
enforce_transaction_limit,verify_claim_signature,calculate_effective_limit
Files:
backend/internal/identity/claims.go- Claim creation, signing, and verificationbackend/internal/identity/test_utils.go- Test utilities
Key Functions:
CreateClaim- Generate new identity claimsSignClaim- Sign claims with Ed25519VerifyClaim- Verify claim signaturesSerializeClaim- Deterministic serialization
┌─────────────────────────────────────────────────────────────────┐
│ Identity-Aware Limits System │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Off-Chain (Go): │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ KYC Provider │────────▶│ Claim Issuer │ │
│ │ (Didit, etc.) │ │ (Backend) │ │
│ └──────────────────┘ └────────┬─────────┘ │
│ │ │
│ │ Signs Claims │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Identity Claim │ │
│ │ + Signature │ │
│ └────────┬─────────┘ │
│ │ │
│ ─────────────────────────────────────┼────────────────────── │
│ │ Submit │
│ On-Chain (Soroban): ▼ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Escrow Contract │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Identity Verification │ │ │
│ │ │ - Verify signature │ │ │
│ │ │ - Check expiry │ │ │
│ │ │ - Store identity data │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ │ ┌──────────────────────────────────────────────┐ │ │
│ │ │ Limit Enforcement │ │ │
│ │ │ - Calculate effective limits │ │ │
│ │ │ - Enforce on lock_funds │ │ │
│ │ │ - Enforce on release_funds │ │ │
│ │ └──────────────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
| Tier | Level | Default Limit | Description |
|---|---|---|---|
| Unverified | 0 | 100 tokens | Default tier, no KYC |
| Basic | 1 | 1,000 tokens | Basic verification |
| Verified | 2 | 10,000 tokens | Full verification |
| Premium | 3 | 100,000 tokens | Enhanced verification |
- Low Risk (0-69): Standard tier limits apply
- High Risk (70-100): Limits reduced by risk multiplier (default 50%)
Formula: effective_limit = tier_limit * (risk_multiplier / 100)
- Off-Chain: KYC provider verifies user identity
- Off-Chain: Backend creates and signs identity claim
- User: Receives signed claim
- On-Chain: User submits claim to contract
- On-Chain: Contract verifies signature and issuer authorization
- On-Chain: Contract stores tier and risk score
- On-Chain: Limits enforced on all transactions
- On-Chain: Expired claims revert to unverified tier
- Ed25519 Signatures: Cryptographic proof of claim authenticity
- Issuer Authorization: Only trusted issuers can sign valid claims
- Expiry Timestamps: Claims have limited validity period
- Signature Verification: Any tampering invalidates signature
- No PII On-Chain: Only tier and risk score stored
- Event Logging: All actions logged for audit
- 10+ test cases covering all major functionality
- Tests for issuer management, limits, queries, and enforcement
- Edge cases: unverified users, expired claims, boundary values
- Go package includes test key generation
- Helper functions for generating valid test claims
- Signature verification testing
// Tier Limits (in stroops, 7 decimals)
unverified: 100_0000000 // 100 tokens
basic: 1000_0000000 // 1,000 tokens
verified: 10000_0000000 // 10,000 tokens
premium: 100000_0000000 // 100,000 tokens
// Risk Thresholds
high_risk_threshold: 70 // Risk score >= 70 is high risk
high_risk_multiplier: 50 // High risk users get 50% of tier limitAll limits and thresholds can be updated by contract admin without redeployment.
// Create claim
claim, _ := identity.CreateClaim(
userAddress,
identity.TierVerified,
25, // risk score
30 * 24 * time.Hour, // 30 days
)
// Sign claim
signature, _ := identity.SignClaim(claim, issuerPrivateKey)
// Return to user// Submit claim
client.submit_identity_claim(&claim, &signature, &issuer_pubkey);
// Query effective limit
let limit = client.get_effective_limit(&address);
// Lock funds (limit enforced automatically)
client.lock_funds(&depositor, &bounty_id, &amount, &deadline);Potential improvements:
- Multiple concurrent claims per address
- Time-based limits (daily/weekly)
- Graduated limits based on transaction history
- Automated claim renewal
- Multi-signature claim issuance
- Claim revocation mechanism
- Deploy contract with admin address
- Set initial tier limits
- Set risk thresholds
- Authorize initial claim issuer(s)
- Configure backend with issuer private key
- Test claim creation and submission
- Verify limit enforcement
- Monitor events and logs
- Issuer Trust: Authorized issuers perform proper KYC verification
- Admin Trust: Contract admin authorizes only legitimate issuers
- Signature Security: Ed25519 is cryptographically secure
- Time Accuracy: Ledger timestamps are accurate for expiry checks
- No personal information stored on-chain
- Only tier and risk score are public
- KYC data remains with provider
- Claims can be verified without revealing identity
- Regulatory compliance through tiered limits
- Risk management via risk scores
- Audit trail via event logging
- Flexible configuration for different jurisdictions
- No on-chain PII storage
The identity-aware limits feature successfully implements a robust system for enforcing transaction limits based on off-chain identity verification. The implementation includes:
- ✅ Complete on-chain contract functionality
- ✅ Off-chain helper library in Go
- ✅ Comprehensive unit tests
- ✅ Detailed documentation
- ✅ Security considerations
- ✅ Integration examples
- ✅ 7 well-structured commits
The system is ready for deployment and integration with KYC providers.