* clear

* feat: Add everything

* fix: Commenht
This commit is contained in:
Prad Nukala
2025-10-03 14:45:52 -04:00
committed by GitHub
parent 43b4a11c06
commit 13e6c3e84d
1935 changed files with 655061 additions and 40058 deletions
+27
View File
@@ -0,0 +1,27 @@
[package]
name = "identity-dao-shared"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
documentation = { workspace = true }
[lib]
crate-type = ["cdylib", "rlib"]
[features]
library = []
[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true }
schemars = { workspace = true }
thiserror = { workspace = true }
[dev-dependencies]
cw-multi-test = { workspace = true }
@@ -0,0 +1,148 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, CustomQuery, Uint128};
/// Custom query for x/did module integration via Stargate
#[cw_serde]
#[derive(QueryResponses)]
pub enum SonrQuery {
/// Query DID document by DID
#[returns(DIDDocumentResponse)]
GetDIDDocument { did: String },
/// Query if DID is verified
#[returns(VerificationResponse)]
IsDIDVerified { did: String },
/// Query DID by address
#[returns(DIDByAddressResponse)]
GetDIDByAddress { address: String },
/// Query all DIDs with pagination
#[returns(DIDsResponse)]
ListDIDs {
start_after: Option<String>,
limit: Option<u32>,
},
/// Query WebAuthn credentials for DID
#[returns(WebAuthnCredentialsResponse)]
GetWebAuthnCredentials { did: String },
}
impl CustomQuery for SonrQuery {}
/// DID Document response
#[cw_serde]
pub struct DIDDocumentResponse {
pub did: String,
pub controller: String,
pub verification_methods: Vec<VerificationMethod>,
pub authentication: Vec<String>,
pub assertion_method: Vec<String>,
pub capability_invocation: Vec<String>,
pub capability_delegation: Vec<String>,
pub service: Vec<Service>,
}
/// Verification method in DID document
#[cw_serde]
pub struct VerificationMethod {
pub id: String,
pub controller: String,
pub method_type: String,
pub public_key: String,
}
/// Service endpoint in DID document
#[cw_serde]
pub struct Service {
pub id: String,
pub service_type: String,
pub service_endpoint: String,
}
/// DID verification response
#[cw_serde]
pub struct VerificationResponse {
pub is_verified: bool,
pub verification_level: u8,
pub last_verified: Option<u64>,
}
/// DID by address response
#[cw_serde]
pub struct DIDByAddressResponse {
pub did: Option<String>,
pub address: String,
}
/// List of DIDs response
#[cw_serde]
pub struct DIDsResponse {
pub dids: Vec<DIDInfo>,
pub total: u64,
}
/// Basic DID information
#[cw_serde]
pub struct DIDInfo {
pub did: String,
pub controller: Addr,
pub created_at: u64,
pub updated_at: u64,
}
/// WebAuthn credentials response
#[cw_serde]
pub struct WebAuthnCredentialsResponse {
pub credentials: Vec<WebAuthnCredential>,
}
/// WebAuthn credential
#[cw_serde]
pub struct WebAuthnCredential {
pub credential_id: String,
pub public_key: String,
pub attestation_type: String,
pub user_verified: bool,
}
/// Stargate query wrapper for x/did module
#[cw_serde]
pub struct StargateQuery {
/// Path to the module query endpoint
pub path: String,
/// Protobuf encoded query data
pub data: Vec<u8>,
}
/// Helper to create stargate queries for x/did module
pub mod stargate {
use super::*;
/// Query path for x/did module
pub const DID_MODULE_PATH: &str = "/sonr.did.v1.Query";
/// Create a stargate query for DID document
pub fn query_did_document(did: &str) -> StargateQuery {
StargateQuery {
path: format!("{}/DIDDocument", DID_MODULE_PATH),
data: encode_did_query(did),
}
}
/// Create a stargate query for DID verification
pub fn query_did_verification(did: &str) -> StargateQuery {
StargateQuery {
path: format!("{}/VerifyDID", DID_MODULE_PATH),
data: encode_did_query(did),
}
}
// Helper to encode DID query (simplified - actual implementation would use prost)
fn encode_did_query(did: &str) -> Vec<u8> {
// This would use prost to encode the protobuf message
// For now, returning a placeholder
did.as_bytes().to_vec()
}
}
@@ -0,0 +1,48 @@
use cosmwasm_std::StdError;
use thiserror::Error;
/// Common errors for Identity DAO contracts
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
#[error("Unauthorized")]
Unauthorized {},
#[error("Invalid DID: {did}")]
InvalidDID { did: String },
#[error("DID not verified")]
DIDNotVerified {},
#[error("Insufficient voting power")]
InsufficientVotingPower {},
#[error("Proposal not found")]
ProposalNotFound {},
#[error("Voting period ended")]
VotingPeriodEnded {},
#[error("Voting period not ended")]
VotingPeriodNotEnded {},
#[error("Already voted")]
AlreadyVoted {},
#[error("Invalid threshold")]
InvalidThreshold {},
#[error("No attestation found for DID: {did}")]
NoAttestation { did: String },
#[error("Custom error: {msg}")]
CustomError { msg: String },
#[error("Invalid IBC channel")]
InvalidIbcChannel {},
#[error("Invalid IBC packet: {error}")]
InvalidIbcPacket { error: String },
}
+12
View File
@@ -0,0 +1,12 @@
/// Shared types and utilities for Identity DAO contracts
pub mod msg;
pub mod query;
pub mod bindings;
pub mod types;
pub mod error;
pub use msg::*;
pub use query::*;
pub use bindings::*;
pub use types::*;
pub use error::*;
+156
View File
@@ -0,0 +1,156 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Binary, Uint128};
use crate::types::{Vote, VotingConfig, VerificationStatus};
/// Core DAO instantiate message
#[cw_serde]
pub struct CoreInstantiateMsg {
/// Name of the DAO
pub name: String,
/// Description of the DAO
pub description: String,
/// Initial voting configuration
pub voting_config: VotingConfig,
/// Admin address (optional)
pub admin: Option<String>,
/// Enable x/did integration
pub enable_did_integration: bool,
}
/// Core DAO execute messages
#[cw_serde]
pub enum CoreExecuteMsg {
/// Execute a proposal
ExecuteProposal { proposal_id: u64 },
/// Update voting configuration
UpdateConfig { voting_config: VotingConfig },
/// Update module addresses
UpdateModules {
voting_module: Option<String>,
proposal_module: Option<String>,
pre_propose_module: Option<String>,
},
/// Transfer treasury funds
TransferFunds {
recipient: String,
amount: Uint128,
},
}
/// Voting module instantiate message
#[cw_serde]
pub struct VotingInstantiateMsg {
/// Core DAO contract address
pub dao_core: String,
/// Minimum verification level required to vote
pub min_verification_level: u8,
/// Enable reputation-based voting weight
pub use_reputation_weight: bool,
}
/// Voting module execute messages
#[cw_serde]
pub enum VotingExecuteMsg {
/// Cast a vote
Vote {
proposal_id: u64,
vote: Vote,
},
/// Update voter registration
UpdateVoter {
did: String,
address: String,
},
/// Remove voter
RemoveVoter { did: String },
}
/// Proposal module instantiate message
#[cw_serde]
pub struct ProposalInstantiateMsg {
/// Core DAO contract address
pub dao_core: String,
/// Voting module address
pub voting_module: String,
/// Pre-propose module address
pub pre_propose_module: Option<String>,
/// Allow multiple choice proposals
pub allow_multiple_choice: bool,
}
/// Proposal module execute messages
#[cw_serde]
pub enum ProposalExecuteMsg {
/// Create a new proposal
Propose {
title: String,
description: String,
msgs: Vec<ProposalMessage>,
},
/// Execute a passed proposal
Execute { proposal_id: u64 },
/// Close an expired proposal
Close { proposal_id: u64 },
/// Update proposal status
UpdateStatus {
proposal_id: u64,
status: ProposalStatusUpdate,
},
}
/// Pre-propose module instantiate message
#[cw_serde]
pub struct PreProposeInstantiateMsg {
/// Proposal module address
pub proposal_module: String,
/// Minimum verification status required
pub min_verification_status: VerificationStatus,
/// Deposit required for proposal
pub deposit_amount: Uint128,
/// Deposit denom
pub deposit_denom: String,
}
/// Pre-propose module execute messages
#[cw_serde]
pub enum PreProposeExecuteMsg {
/// Submit a proposal for approval
SubmitProposal {
title: String,
description: String,
msgs: Vec<ProposalMessage>,
},
/// Approve a pending proposal
ApproveProposal { proposal_id: u64 },
/// Reject a pending proposal
RejectProposal {
proposal_id: u64,
reason: String,
},
/// Withdraw a pending proposal
WithdrawProposal { proposal_id: u64 },
}
/// Message to be executed by a proposal
#[cw_serde]
pub struct ProposalMessage {
/// Contract address to execute on
pub contract: String,
/// Message to execute
pub msg: Binary,
/// Funds to send with the message
pub funds: Vec<cosmwasm_std::Coin>,
}
/// Proposal status update
#[cw_serde]
pub enum ProposalStatusUpdate {
/// Mark as passed
Passed,
/// Mark as rejected
Rejected,
/// Mark as executed
Executed,
/// Mark as failed
ExecutionFailed { reason: String },
}
+237
View File
@@ -0,0 +1,237 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Uint128};
use crate::types::{
IdentityVoter, ProposalStatus, Vote, VotingConfig,
IdentityAttestation, TreasuryInfo, ModuleConfig
};
/// Core DAO query messages
#[cw_serde]
#[derive(QueryResponses)]
pub enum CoreQueryMsg {
/// Get DAO configuration
#[returns(DaoConfigResponse)]
Config {},
/// Get treasury information
#[returns(TreasuryInfo)]
Treasury {},
/// Get module addresses
#[returns(ModuleConfig)]
Modules {},
/// Get DAO stats
#[returns(DaoStatsResponse)]
Stats {},
}
/// Voting module query messages
#[cw_serde]
#[derive(QueryResponses)]
pub enum VotingQueryMsg {
/// Get voting power for a DID
#[returns(VotingPowerResponse)]
VotingPower { did: String },
/// Get total voting power
#[returns(TotalPowerResponse)]
TotalPower { height: Option<u64> },
/// Get voter info
#[returns(VoterInfoResponse)]
VoterInfo { did: String },
/// List all voters with pagination
#[returns(VotersListResponse)]
ListVoters {
start_after: Option<String>,
limit: Option<u32>,
},
/// Get vote on a proposal
#[returns(VoteResponse)]
Vote {
proposal_id: u64,
voter: String,
},
}
/// Proposal module query messages
#[cw_serde]
#[derive(QueryResponses)]
pub enum ProposalQueryMsg {
/// Get proposal details
#[returns(ProposalResponse)]
Proposal { proposal_id: u64 },
/// List proposals with filters
#[returns(ProposalsListResponse)]
ListProposals {
status: Option<ProposalStatus>,
start_after: Option<u64>,
limit: Option<u32>,
},
/// Get proposal votes
#[returns(ProposalVotesResponse)]
ProposalVotes {
proposal_id: u64,
start_after: Option<String>,
limit: Option<u32>,
},
/// Get proposal result
#[returns(ProposalResultResponse)]
ProposalResult { proposal_id: u64 },
}
/// Pre-propose module query messages
#[cw_serde]
#[derive(QueryResponses)]
pub enum PreProposeQueryMsg {
/// Get pending proposals
#[returns(PendingProposalsResponse)]
PendingProposals {
start_after: Option<u64>,
limit: Option<u32>,
},
/// Get deposit info
#[returns(DepositInfoResponse)]
DepositInfo { proposer: String },
/// Get module config
#[returns(PreProposeConfigResponse)]
Config {},
}
// Response types
#[cw_serde]
pub struct DaoConfigResponse {
pub name: String,
pub description: String,
pub voting_config: VotingConfig,
pub admin: Option<Addr>,
pub did_integration_enabled: bool,
}
#[cw_serde]
pub struct DaoStatsResponse {
pub total_proposals: u64,
pub active_proposals: u64,
pub total_voters: u64,
pub treasury_balance: Uint128,
}
#[cw_serde]
pub struct VotingPowerResponse {
pub power: Uint128,
pub height: u64,
}
#[cw_serde]
pub struct TotalPowerResponse {
pub power: Uint128,
pub height: u64,
}
#[cw_serde]
pub struct VoterInfoResponse {
pub voter: IdentityVoter,
pub proposals_voted: u64,
}
#[cw_serde]
pub struct VotersListResponse {
pub voters: Vec<IdentityVoter>,
pub total: u64,
}
#[cw_serde]
pub struct VoteResponse {
pub vote: Option<VoteInfo>,
}
#[cw_serde]
pub struct VoteInfo {
pub proposal_id: u64,
pub voter: String,
pub vote: Vote,
pub voting_power: Uint128,
}
#[cw_serde]
pub struct ProposalResponse {
pub id: u64,
pub title: String,
pub description: String,
pub proposer: String,
pub status: ProposalStatus,
pub votes: ProposalVotes,
pub start_time: u64,
pub end_time: u64,
}
#[cw_serde]
pub struct ProposalVotes {
pub yes: Uint128,
pub no: Uint128,
pub abstain: Uint128,
pub no_with_veto: Uint128,
}
#[cw_serde]
pub struct ProposalsListResponse {
pub proposals: Vec<ProposalResponse>,
pub total: u64,
}
#[cw_serde]
pub struct ProposalVotesResponse {
pub votes: Vec<VoteInfo>,
pub total: u64,
}
#[cw_serde]
pub struct ProposalResultResponse {
pub proposal_id: u64,
pub result: ProposalResult,
}
#[cw_serde]
pub enum ProposalResult {
Passed,
Rejected,
InProgress,
}
#[cw_serde]
pub struct PendingProposalsResponse {
pub proposals: Vec<PendingProposal>,
pub total: u64,
}
#[cw_serde]
pub struct PendingProposal {
pub id: u64,
pub proposer: String,
pub title: String,
pub submitted_at: u64,
}
#[cw_serde]
pub struct DepositInfoResponse {
pub depositor: String,
pub amount: Uint128,
pub refundable: bool,
}
#[cw_serde]
pub struct PreProposeConfigResponse {
pub proposal_module: Addr,
pub min_verification_status: String,
pub deposit_amount: Uint128,
pub deposit_denom: String,
}
+127
View File
@@ -0,0 +1,127 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, Timestamp, Uint128};
/// Represents a DID holder with voting power
#[cw_serde]
pub struct IdentityVoter {
/// DID of the voter
pub did: String,
/// Address associated with the DID
pub address: Addr,
/// Voting power based on identity attributes
pub voting_power: Uint128,
/// Verification level (0-100)
pub verification_level: u8,
/// Reputation score
pub reputation_score: u64,
}
/// Identity verification status
#[cw_serde]
pub enum VerificationStatus {
/// Not verified
Unverified,
/// Basic verification completed
Basic,
/// Advanced verification with KYC
Advanced,
/// Full verification with attestations
Full,
}
/// Proposal status in the DAO
#[cw_serde]
pub enum ProposalStatus {
/// Pending approval from pre-propose module
Pending,
/// Open for voting
Open,
/// Voting period ended, waiting execution
Passed,
/// Proposal rejected
Rejected,
/// Proposal executed
Executed,
/// Proposal execution failed
ExecutionFailed,
}
/// Vote option
#[cw_serde]
pub enum Vote {
Yes,
No,
Abstain,
NoWithVeto,
}
/// Voting configuration
#[cw_serde]
pub struct VotingConfig {
/// Minimum percentage of yes votes required
pub threshold: Decimal,
/// Minimum voter turnout percentage
pub quorum: Decimal,
/// Voting duration in seconds
pub voting_period: u64,
/// Proposal deposit amount
pub proposal_deposit: Uint128,
}
/// Identity attestation
#[cw_serde]
pub struct IdentityAttestation {
/// DID being attested
pub did: String,
/// Attester's DID
pub attester_did: String,
/// Type of attestation
pub attestation_type: AttestationType,
/// Attestation data
pub data: String,
/// Timestamp of attestation
pub timestamp: Timestamp,
/// Expiration time
pub expires_at: Option<Timestamp>,
}
/// Types of attestations
#[cw_serde]
pub enum AttestationType {
/// Identity verification
Identity,
/// Skill or credential
Credential,
/// Reputation endorsement
Reputation,
/// Custom attestation
Custom(String),
}
/// DAO treasury info
#[cw_serde]
pub struct TreasuryInfo {
/// Treasury address
pub address: Addr,
/// Available balance
pub balance: Uint128,
/// Reserved funds for proposals
pub reserved: Uint128,
}
/// Module configuration
#[cw_serde]
pub struct ModuleConfig {
/// Core DAO contract address
pub dao_core: Addr,
/// Voting module address
pub voting_module: Addr,
/// Proposal module address
pub proposal_module: Addr,
/// Pre-propose module address
pub pre_propose_module: Addr,
/// x/did module integration enabled
pub did_integration_enabled: bool,
}
use cosmwasm_std::Decimal;