* 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
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/make -f
# Docker configuration
DOCKER := $(shell which docker)
CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)
# Proto builder configuration
protoVer=0.13.2
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage="$(DOCKER)" run -e BUF_CACHE_DIR=/tmp/buf --rm -v "$(GIT_ROOT)":/workspace:rw --user ${CURRENT_UID}:${CURRENT_GID} --workdir /workspace $(protoImageName)
# Spawn configuration
spawnImage="$(DOCKER)" run --rm -v "$(GIT_ROOT)":/workspace:rw --user ${CURRENT_UID}:${CURRENT_GID} --workdir /workspace -e HOME=/workspace onsonr/spawn:latest
# Git configuration
HTTPS_GIT := github.com/sonr-io/sonr.git
GIT_ROOT := $(shell git rev-parse --show-toplevel)
###############################################################################
### Default Target ###
###############################################################################
.DEFAULT_GOAL := help
all: build gen swagger-gen push
proto: gen
generate: gen
###############################################################################
### Code Generation ###
###############################################################################
build:
@gum log --level info "Building Protobuf files"
@npx buf build
gen:
@go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@v1.0.0-beta.3
@gum log --level info "Generating Protobuf files"
@$(protoImage) sh /workspace/scripts/protocgen.sh
@gum log --level info "Generating stubs with spawn..."
@$(spawnImage) spawn stub-gen
@cd $(GIT_ROOT) && go mod tidy
###############################################################################
### Linting ###
###############################################################################
lint:
@$(protoImage) buf lint --error-format=json
test:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
###############################################################################
### Documentation ###
###############################################################################
swagger-gen:
@gum log --level info "Generating OpenAPI documentation..."
@buf generate --template buf.gen.openapi.yaml
@gum log --level info "✅ OpenAPI documentation generated in docs/static/openapi/"
@gum log --level info "✅ Merged API specification: docs/static/openapi/sonr.swagger.yaml"
push:
@npx buf push
release:
@gum log --level info "Releasing Protobuf files"
@npx buf build
@npx buf push
###############################################################################
### Help ###
###############################################################################
help:
@gum log --level info "Sonr Protocol Buffer Management"
@gum log --level info ""
@gum log --level info "Usage: make [target]"
@gum log --level info ""
@gum log --level info "Available targets:"
@gum log --level info ""
@gum log --level info " all Run lint, gen, and swagger-gen targets"
@gum log --level info " gen Generate protobuf code and stubs"
@gum log --level info " lint Lint protobuf files"
@gum log --level info " check-breaking Check for breaking changes against main branch"
@gum log --level info " swagger-gen Generate OpenAPI documentation"
@gum log --level info " help Show this help message"
@gum log --level info ""
@gum log --level info "Environment:"
@gum log --level info " Proto builder: $(protoImageName)"
@gum log --level info " Spawn: onsonr/spawn:latest"
.PHONY: all gen lint check-breaking swagger-gen help
-19
View File
@@ -1,19 +0,0 @@
# Sonr Protobuf
## Overview
This directory contains the protobuf definitions for the Sonr blockchain.
## Directory Structure
### `did`
The `did` directory contains the protobuf definitions for the DID module.
### `dwn`
The `dwn` directory contains the protobuf definitions for the Vault module.
### `svc`
The `service` directory contains the protobuf definitions for the Service module.
Regular → Executable
View File
+28
View File
@@ -0,0 +1,28 @@
version: v1
plugins:
# Generate OpenAPI v2 (Swagger) documentation
- name: openapiv2
out: ../docs/static/openapi
opt:
- logtostderr=true
- simple_operation_ids=true
- openapi_naming_strategy=simple
- json_names_for_fields=true
- allow_merge=false
- output_format=yaml
# Generate methods without HTTP bindings
- generate_unbound_methods=true
# Include service tags
- disable_service_tags=false
# Preserve RPC order
- preserve_rpc_order=true
# Only generate for files with actual services
- include_package_in_tags=false
# Go package mappings
- Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types
- Mcosmos/app/v1alpha1/module.proto=cosmossdk.io/api/cosmos/app/v1alpha1
- Mcosmos/orm/v1/orm.proto=cosmossdk.io/orm
- Mdex/module/v1/module.proto=github.com/sonr-io/sonr/x/dex
- Mdid/module/v1/module.proto=github.com/sonr-io/sonr/x/did
- Mdwn/module/v1/module.proto=github.com/sonr-io/sonr/x/dwn
- Msvc/module/v1/module.proto=github.com/sonr-io/sonr/x/svc
Regular → Executable
+2 -1
View File
@@ -2,7 +2,7 @@ version: v1
managed:
enabled: true
go_package_prefix:
default: github.com/sonr-io/snrd/api
default: github.com/sonr-io/sonr/api
except:
- buf.build/googleapis/googleapis
- buf.build/cosmos/gogo-proto
@@ -16,6 +16,7 @@ plugins:
- name: go-grpc
out: ..
opt: paths=source_relative
# go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@latest
- name: go-cosmos-orm
out: ..
opt: paths=source_relative
Regular → Executable
+4 -18
View File
@@ -4,30 +4,16 @@ deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 04467658e59e44bbb22fe568206e1f70
digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466
commit: 1935555c206d4afb9e94615dfd0fad31
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 05419252bcc241ea8023acf1ed4cadc5
digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5
commit: d5661b4f6ef64bb1b5beb6cb7bd705b7
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: 88ef6483f90f478fb938c37dde52ece3
digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba
commit: 5e5b9fdd01804356895f8f79a6f1ddc1
- remote: buf.build
owner: googleapis
repository: googleapis
commit: c0913f24652a4cfc95f77d97443a5005
digest: shake256:0ef3248c6235d420fe61f373154adcde6b94e3297f82472b1d8d8c3747240b61b4a10405e2a6f8ac1c98816ac6e690ea7871024aa5ae0e035cd540214667ceed
- remote: buf.build
owner: protocolbuffers
repository: wellknowntypes
commit: 657250e6a39648cbb169d079a60bd9ba
digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb
- remote: buf.build
owner: tendermint
repository: tendermint
commit: 33ed361a90514289beabf3189e1d7665
digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d
commit: cc916c31859748a68fd229a3c8d7a2e8
Regular → Executable
+2 -20
View File
@@ -1,13 +1,11 @@
version: v1
name: buf.build/onsonr/sonr
name: buf.build/sonr-io/sonr
deps:
- buf.build/cosmos/cosmos-sdk
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/gogo-proto
- buf.build/googleapis/googleapis
breaking:
use:
- FILE
- buf.build/grpc-ecosystem/grpc-gateway
lint:
use:
- DEFAULT
@@ -16,22 +14,6 @@ lint:
except:
- UNARY_RPC
- COMMENT_FIELD
- COMMENT_MESSAGE
- COMMENT_SERVICE
- COMMENT_RPC
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- PACKAGE_SAME_GO_PACKAGE
- PACKAGE_SAME_DIRECTORY
- PACKAGE_DIRECTORY_MATCH
- RPC_RESPONSE_STANDARD_NAME
- COMMENT_ENUM_VALUE
- COMMENT_ENUM
- ENUM_ZERO_VALUE_SUFFIX
ignore:
- PACKAGE_NO_IMPORT_CYCLE
- IMPORT_USED
- tendermint
- amino
- cosmos
+13
View File
@@ -0,0 +1,13 @@
syntax = "proto3";
package dex.module.v1;
import "cosmos/app/v1alpha1/module.proto";
// Module is the app config object of the module.
// Learn more: https://docs.cosmos.network/main/building-modules/depinject
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import : "github.com/sonr-io/sonr"
};
}
+65
View File
@@ -0,0 +1,65 @@
## Overview
Query endpoints for the DEX module provide read-only access to decentralized exchange state and operations.
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Query Details
{{if eq .MethodDescriptorProto.Name "Params"}}
- Returns the current module parameters
- Includes fee configurations and operational settings
- No authentication required for parameter queries
{{else if eq .MethodDescriptorProto.Name "Account"}}
- Retrieves a specific DEX account by DID and connection
- Returns ICA account details and status
- Shows linked features and capabilities
{{else if eq .MethodDescriptorProto.Name "Accounts"}}
- Lists all DEX accounts for a given DID
- Supports pagination for large result sets
- Returns accounts across all connected chains
{{else if eq .MethodDescriptorProto.Name "Balance"}}
- Queries balance on remote chain through ICA
- Can filter by specific denomination
- Returns real-time balance information
{{else if eq .MethodDescriptorProto.Name "Pool"}}
- Retrieves detailed pool information
- Shows current liquidity and swap fees
- Returns asset composition and total shares
{{else if eq .MethodDescriptorProto.Name "Orders"}}
- Lists orders for a specific DID and connection
- Supports filtering by order status
- Returns paginated order history
{{else if eq .MethodDescriptorProto.Name "History"}}
- Provides transaction history across all DEX operations
- Supports filtering by connection and operation type
- Returns detailed transaction records with timestamps
{{end}}
## Usage Examples
```bash
# Query module parameters
snrd query dex params
# Get specific DEX account
snrd query dex account did:sonr:123 connection-0
# Check balance on remote chain
snrd query dex balance did:sonr:123 connection-0 --denom uatom
# Query pool information
snrd query dex pool connection-0 pool-1
# List orders
snrd query dex orders did:sonr:123 connection-0
```
+50
View File
@@ -0,0 +1,50 @@
## Overview
The DEX module enables decentralized exchange operations across multiple chains via IBC (Inter-Blockchain Communication).
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Implementation Notes
{{if eq .MethodDescriptorProto.Name "RegisterDEXAccount"}}
- Creates an ICA (Interchain Account) for DEX operations on remote chains
- Establishes secure cross-chain communication channels
- Supports configurable feature sets for different DEX capabilities
{{else if eq .MethodDescriptorProto.Name "ExecuteSwap"}}
- Performs atomic token swaps on remote DEX platforms
- Includes slippage protection via minimum output amount
- Supports custom routing for optimal price execution
- UCAN token authorization ensures secure delegation
{{else if eq .MethodDescriptorProto.Name "ProvideLiquidity"}}
- Adds liquidity to AMM (Automated Market Maker) pools
- Returns LP (Liquidity Provider) tokens as proof of deposit
- Protects against slippage during liquidity provision
{{else if eq .MethodDescriptorProto.Name "RemoveLiquidity"}}
- Withdraws liquidity from pools using LP tokens
- Ensures minimum asset amounts to protect against losses
- Supports partial and full liquidity removal
{{else if eq .MethodDescriptorProto.Name "CreateLimitOrder"}}
- Places limit orders on remote orderbook DEXs
- Supports time-based expiration for orders
- Automatically executes when price conditions are met
{{else if eq .MethodDescriptorProto.Name "CancelOrder"}}
- Cancels pending limit orders before execution
- Returns unfilled assets to user's account
- Requires proper authorization via UCAN token
{{end}}
## Security Considerations
- All operations require UCAN authorization tokens for delegation
- IBC packet timeouts prevent stuck transactions
- Connection IDs must reference valid, established IBC channels
- DID-based authentication ensures identity verification
+179
View File
@@ -0,0 +1,179 @@
syntax = "proto3";
package dex.v1;
option go_package = "github.com/sonr-io/sonr/x/dex/types";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
// EventDEXAccountRegistered is emitted when a new DEX account is registered
message EventDEXAccountRegistered {
// DID of the account owner
string did = 1;
// IBC connection ID
string connection_id = 2;
// Generated port ID
string port_id = 3;
// Remote account address (when available)
string account_address = 4;
}
// EventSwapExecuted is emitted when a swap is executed
message EventSwapExecuted {
// DID of the trader
string did = 1;
// IBC connection ID
string connection_id = 2;
// Source token and amount
cosmos.base.v1beta1.Coin source = 3 [(gogoproto.nullable) = false];
// Target token and amount received
cosmos.base.v1beta1.Coin target = 4 [(gogoproto.nullable) = false];
// Transaction hash on remote chain
string tx_hash = 5;
// IBC packet sequence
uint64 sequence = 6;
}
// EventLiquidityProvided is emitted when liquidity is added
message EventLiquidityProvided {
// DID of the liquidity provider
string did = 1;
// IBC connection ID
string connection_id = 2;
// Pool ID
string pool_id = 3;
// Assets provided
repeated cosmos.base.v1beta1.Coin assets = 4
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// Shares received
string shares_received = 5;
// Transaction hash on remote chain
string tx_hash = 6;
}
// EventLiquidityRemoved is emitted when liquidity is removed
message EventLiquidityRemoved {
// DID of the liquidity provider
string did = 1;
// IBC connection ID
string connection_id = 2;
// Pool ID
string pool_id = 3;
// Shares removed
string shares_removed = 4;
// Assets received
repeated cosmos.base.v1beta1.Coin assets = 5
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// Transaction hash on remote chain
string tx_hash = 6;
}
// EventOrderCreated is emitted when a limit order is created
message EventOrderCreated {
// DID of the trader
string did = 1;
// IBC connection ID
string connection_id = 2;
// Order ID on remote chain
string order_id = 3;
// Order details
string sell_denom = 4;
string buy_denom = 5;
string amount = 6;
string price = 7;
// Transaction hash on remote chain
string tx_hash = 8;
}
// EventOrderCancelled is emitted when an order is cancelled
message EventOrderCancelled {
// DID of the trader
string did = 1;
// IBC connection ID
string connection_id = 2;
// Order ID that was cancelled
string order_id = 3;
// Transaction hash on remote chain
string tx_hash = 4;
}
// EventOrderFilled is emitted when an order is filled
message EventOrderFilled {
// DID of the trader
string did = 1;
// IBC connection ID
string connection_id = 2;
// Order ID that was filled
string order_id = 3;
// Fill details
string fill_amount = 4;
string fill_price = 5;
// Transaction hash on remote chain
string tx_hash = 6;
}
// EventICAPacketSent is emitted when an ICA packet is sent
message EventICAPacketSent {
// DID of the sender
string did = 1;
// IBC connection ID
string connection_id = 2;
// Packet type (swap, liquidity, order, etc.)
string packet_type = 3;
// IBC packet sequence
uint64 sequence = 4;
}
// EventICAPacketAcknowledged is emitted when an ICA packet is acknowledged
message EventICAPacketAcknowledged {
// DID of the sender
string did = 1;
// IBC connection ID
string connection_id = 2;
// Packet type
string packet_type = 3;
// IBC packet sequence
uint64 sequence = 4;
// Success status
bool success = 5;
// Error message if failed
string error = 6;
}
+79
View File
@@ -0,0 +1,79 @@
syntax = "proto3";
package dex.v1;
option go_package = "github.com/sonr-io/sonr/x/dex/types";
import "gogoproto/gogo.proto";
import "dex/v1/ica.proto";
// GenesisState defines the DEX module's genesis state
message GenesisState {
// Module parameters
Params params = 1 [(gogoproto.nullable) = false];
// IBC port ID for the module
string port_id = 2;
// Registered DEX accounts
repeated InterchainDEXAccount accounts = 3;
// Account sequence counter
uint64 account_sequence = 4;
}
// Params defines the parameters for the DEX module
message Params {
option (gogoproto.goproto_getters) = false;
// Enable/disable the module
bool enabled = 1;
// Maximum accounts per DID
uint32 max_accounts_per_did = 2;
// Default timeout for ICA operations (in seconds)
uint64 default_timeout_seconds = 3;
// Allowed DEX connections
repeated string allowed_connections = 4;
// Minimum swap amount (in base denom)
string min_swap_amount = 5;
// Maximum daily volume per DID (in USD equivalent)
string max_daily_volume = 6;
// Rate limit parameters
RateLimitParams rate_limits = 7 [(gogoproto.nullable) = false];
// Fee parameters
FeeParams fees = 8 [(gogoproto.nullable) = false];
}
// RateLimitParams defines rate limiting parameters
message RateLimitParams {
// Maximum operations per block
uint32 max_ops_per_block = 1;
// Maximum operations per DID per day
uint32 max_ops_per_did_per_day = 2;
// Cooldown period between operations (in blocks)
uint32 cooldown_blocks = 3;
}
// FeeParams defines fee parameters for DEX operations
message FeeParams {
// Platform fee for swaps (basis points, e.g., 30 = 0.3%)
uint32 swap_fee_bps = 1;
// Platform fee for liquidity operations
uint32 liquidity_fee_bps = 2;
// Platform fee for orders
uint32 order_fee_bps = 3;
// Fee collector address
string fee_collector = 4;
}
+113
View File
@@ -0,0 +1,113 @@
syntax = "proto3";
package dex.v1;
option go_package = "github.com/sonr-io/sonr/x/dex/types";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
// InterchainDEXAccount represents a DEX account on a remote chain
message InterchainDEXAccount {
option (gogoproto.goproto_getters) = false;
// DID controller of this account
string did = 1;
// IBC connection to the remote chain
string connection_id = 2;
// Remote chain ID (e.g., osmosis-1)
string host_chain_id = 3;
// Account address on the remote chain
string account_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// ICA port ID for this account
string port_id = 5;
// Account creation timestamp
google.protobuf.Timestamp created_at = 6
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// Enabled features for this account
repeated string enabled_features = 7;
// Account status
AccountStatus status = 8;
}
// AccountStatus defines the status of an ICA account
enum AccountStatus {
option (gogoproto.goproto_enum_prefix) = false;
// Account is pending creation
ACCOUNT_STATUS_PENDING = 0;
// Account is active and ready
ACCOUNT_STATUS_ACTIVE = 1;
// Account is temporarily disabled
ACCOUNT_STATUS_DISABLED = 2;
// Account creation failed
ACCOUNT_STATUS_FAILED = 3;
}
// DEXFeatures defines available features for DEX accounts
enum DEXFeatures {
option (gogoproto.goproto_enum_prefix) = false;
// Basic swap functionality
DEX_FEATURE_SWAP = 0;
// Liquidity provision
DEX_FEATURE_LIQUIDITY = 1;
// Limit orders
DEX_FEATURE_ORDERS = 2;
// Staking operations
DEX_FEATURE_STAKING = 3;
// Governance participation
DEX_FEATURE_GOVERNANCE = 4;
}
// DEXActivity represents a DEX operation activity record
message DEXActivity {
// Type of activity (swap, provide_liquidity, remove_liquidity, create_order, cancel_order)
string type = 1;
// DID that performed the activity
string did = 2;
// Connection ID where the activity occurred
string connection_id = 3;
// Transaction hash of the activity
string tx_hash = 4;
// Block height when the activity occurred
int64 block_height = 5;
// Timestamp of the activity
google.protobuf.Timestamp timestamp = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Activity-specific details (JSON encoded)
string details = 7;
// Status of the activity (pending, success, failed)
string status = 8;
// Amount involved in the activity (if applicable)
repeated cosmos.base.v1beta1.Coin amount = 9 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
// Gas used for the activity
uint64 gas_used = 10;
}
+273
View File
@@ -0,0 +1,273 @@
syntax = "proto3";
package dex.v1;
option go_package = "github.com/sonr-io/sonr/x/dex/types";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "dex/v1/genesis.proto";
import "dex/v1/ica.proto";
import "cosmos/base/v1beta1/coin.proto";
// Query defines the DEX Query service
service Query {
// Params queries the parameters of the module
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/sonr/dex/v1/params";
}
// Account queries a DEX account by DID and connection
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Account(QueryAccountRequest) returns (QueryAccountResponse) {
option (google.api.http).get = "/sonr/dex/v1/account/{did}/{connection_id}";
}
// Accounts queries all DEX accounts for a DID
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Accounts(QueryAccountsRequest) returns (QueryAccountsResponse) {
option (google.api.http).get = "/sonr/dex/v1/accounts/{did}";
}
// Balance queries remote chain balance
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Balance(QueryBalanceRequest) returns (QueryBalanceResponse) {
option (google.api.http).get = "/sonr/dex/v1/balance/{did}/{connection_id}";
}
// Pool queries pool information
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Pool(QueryPoolRequest) returns (QueryPoolResponse) {
option (google.api.http).get = "/sonr/dex/v1/pool/{connection_id}/{pool_id}";
}
// Orders queries orders for a DID
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc Orders(QueryOrdersRequest) returns (QueryOrdersResponse) {
option (google.api.http).get = "/sonr/dex/v1/orders/{did}/{connection_id}";
}
// History queries transaction history
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_query_docs.md"}}
rpc History(QueryHistoryRequest) returns (QueryHistoryResponse) {
option (google.api.http).get = "/sonr/dex/v1/history/{did}";
}
}
// QueryParamsRequest is request type for Query/Params RPC method
message QueryParamsRequest {}
// QueryParamsResponse is response type for Query/Params RPC method
message QueryParamsResponse {
// params holds all the parameters of this module
Params params = 1 [(gogoproto.nullable) = false];
}
// QueryAccountRequest is request type for Query/Account RPC method
message QueryAccountRequest {
// DID of the account owner
string did = 1;
// IBC connection ID
string connection_id = 2;
}
// QueryAccountResponse is response type for Query/Account RPC method
message QueryAccountResponse {
// The DEX account
InterchainDEXAccount account = 1;
}
// QueryAccountsRequest is request type for Query/Accounts RPC method
message QueryAccountsRequest {
// DID of the account owner
string did = 1;
// pagination defines optional pagination
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryAccountsResponse is response type for Query/Accounts RPC method
message QueryAccountsResponse {
// List of DEX accounts
repeated InterchainDEXAccount accounts = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryBalanceRequest is request type for Query/Balance RPC method
message QueryBalanceRequest {
// DID of the account owner
string did = 1;
// IBC connection ID
string connection_id = 2;
// Optional specific denom to query
string denom = 3;
}
// QueryBalanceResponse is response type for Query/Balance RPC method
message QueryBalanceResponse {
// Balances on the remote chain
repeated cosmos.base.v1beta1.Coin balances = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}
// QueryPoolRequest is request type for Query/Pool RPC method
message QueryPoolRequest {
// IBC connection ID
string connection_id = 1;
// Pool ID to query
string pool_id = 2;
}
// QueryPoolResponse is response type for Query/Pool RPC method
message QueryPoolResponse {
// Pool information
PoolInfo pool = 1;
}
// PoolInfo contains pool information
message PoolInfo {
// Pool ID
string pool_id = 1;
// Pool assets
repeated cosmos.base.v1beta1.Coin assets = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// Total shares
string total_shares = 3;
// Swap fee
string swap_fee = 4;
}
// QueryOrdersRequest is request type for Query/Orders RPC method
message QueryOrdersRequest {
// DID of the account owner
string did = 1;
// IBC connection ID
string connection_id = 2;
// Filter by status (optional)
string status = 3;
// pagination defines optional pagination
cosmos.base.query.v1beta1.PageRequest pagination = 4;
}
// QueryOrdersResponse is response type for Query/Orders RPC method
message QueryOrdersResponse {
// List of orders
repeated Order orders = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// Order represents a DEX order
message Order {
// Order ID
string order_id = 1;
// Order type
string order_type = 2;
// Sell token
string sell_denom = 3;
// Buy token
string buy_denom = 4;
// Amount
string amount = 5;
// Price
string price = 6;
// Status
string status = 7;
// Creation time
string created_at = 8;
}
// QueryHistoryRequest is request type for Query/History RPC method
message QueryHistoryRequest {
// DID of the account owner
string did = 1;
// Optional connection filter
string connection_id = 2;
// Optional operation type filter
string operation_type = 3;
// pagination defines optional pagination
cosmos.base.query.v1beta1.PageRequest pagination = 4;
}
// QueryHistoryResponse is response type for Query/History RPC method
message QueryHistoryResponse {
// List of historical transactions
repeated Transaction transactions = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// Transaction represents a historical transaction
message Transaction {
// Transaction ID
string tx_id = 1;
// Operation type (swap, provide_liquidity, etc.)
string operation_type = 2;
// Connection ID
string connection_id = 3;
// Transaction details (JSON)
string details = 4;
// Status
string status = 5;
// Timestamp
string timestamp = 6;
}
+326
View File
@@ -0,0 +1,326 @@
syntax = "proto3";
package dex.v1;
option go_package = "github.com/sonr-io/sonr/x/dex/types";
import "gogoproto/gogo.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "google/protobuf/timestamp.proto";
// Msg defines the DEX Msg service
service Msg {
option (cosmos.msg.v1.service) = true;
// RegisterDEXAccount creates a new ICA account for DEX operations
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc RegisterDEXAccount(MsgRegisterDEXAccount) returns (MsgRegisterDEXAccountResponse);
// ExecuteSwap performs a token swap on a remote chain
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc ExecuteSwap(MsgExecuteSwap) returns (MsgExecuteSwapResponse);
// ProvideLiquidity adds liquidity to a pool
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc ProvideLiquidity(MsgProvideLiquidity) returns (MsgProvideLiquidityResponse);
// RemoveLiquidity removes liquidity from a pool
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc RemoveLiquidity(MsgRemoveLiquidity) returns (MsgRemoveLiquidityResponse);
// CreateLimitOrder creates a limit order
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc CreateLimitOrder(MsgCreateLimitOrder) returns (MsgCreateLimitOrderResponse);
// CancelOrder cancels an existing order
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dex_tx_docs.md"}}
rpc CancelOrder(MsgCancelOrder) returns (MsgCancelOrderResponse);
}
// MsgRegisterDEXAccount registers a new ICA account for DEX operations
message MsgRegisterDEXAccount {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID controller requesting the account
string did = 1;
// IBC connection to target chain
string connection_id = 2;
// Requested features for this account
repeated string features = 3;
// Optional metadata
string metadata = 4;
}
// MsgRegisterDEXAccountResponse defines the response
message MsgRegisterDEXAccountResponse {
option (gogoproto.goproto_getters) = false;
// Generated port ID for the account
string port_id = 1;
// Account address on remote chain (once available)
string account_address = 2;
}
// MsgExecuteSwap executes a token swap on a remote chain
message MsgExecuteSwap {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID initiating the swap
string did = 1;
// IBC connection to DEX chain
string connection_id = 2;
// Token to swap from
string source_denom = 3;
// Token to swap to
string target_denom = 4;
// Amount to swap
string amount = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// Minimum amount out (slippage protection)
string min_amount_out = 6 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// Optional specific route
string route = 7;
// UCAN authorization token
string ucan_token = 8;
// Timeout for the swap
google.protobuf.Timestamp timeout = 9
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}
// MsgExecuteSwapResponse defines the response
message MsgExecuteSwapResponse {
option (gogoproto.goproto_getters) = false;
// Transaction ID on remote chain
string tx_hash = 1;
// Actual amount received
string amount_received = 2;
// IBC packet sequence
uint64 sequence = 3;
}
// MsgProvideLiquidity adds liquidity to a pool
message MsgProvideLiquidity {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID providing liquidity
string did = 1;
// IBC connection to DEX chain
string connection_id = 2;
// Pool ID to add liquidity to
string pool_id = 3;
// Assets to provide
repeated cosmos.base.v1beta1.Coin assets = 4
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// Minimum shares to receive (slippage protection)
string min_shares = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// UCAN authorization token
string ucan_token = 6;
// Timeout for the operation
google.protobuf.Timestamp timeout = 7
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}
// MsgProvideLiquidityResponse defines the response
message MsgProvideLiquidityResponse {
option (gogoproto.goproto_getters) = false;
// Transaction ID on remote chain
string tx_hash = 1;
// LP tokens received
string shares_received = 2;
// IBC packet sequence
uint64 sequence = 3;
}
// MsgRemoveLiquidity removes liquidity from a pool
message MsgRemoveLiquidity {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID removing liquidity
string did = 1;
// IBC connection to DEX chain
string connection_id = 2;
// Pool ID to remove liquidity from
string pool_id = 3;
// Amount of shares to remove
string shares = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// Minimum assets to receive
repeated cosmos.base.v1beta1.Coin min_amounts = 5
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// UCAN authorization token
string ucan_token = 6;
// Timeout for the operation
google.protobuf.Timestamp timeout = 7
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
}
// MsgRemoveLiquidityResponse defines the response
message MsgRemoveLiquidityResponse {
option (gogoproto.goproto_getters) = false;
// Transaction ID on remote chain
string tx_hash = 1;
// Assets received
repeated cosmos.base.v1beta1.Coin assets_received = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
// IBC packet sequence
uint64 sequence = 3;
}
// MsgCreateLimitOrder creates a limit order
message MsgCreateLimitOrder {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID creating the order
string did = 1;
// IBC connection to DEX chain
string connection_id = 2;
// Token to sell
string sell_denom = 3;
// Token to buy
string buy_denom = 4;
// Amount to sell
string amount = 5 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
// Price per unit
string price = 6 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// Order expiration
google.protobuf.Timestamp expiration = 7
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
// UCAN authorization token
string ucan_token = 8;
}
// MsgCreateLimitOrderResponse defines the response
message MsgCreateLimitOrderResponse {
option (gogoproto.goproto_getters) = false;
// Order ID on remote chain
string order_id = 1;
// Transaction ID
string tx_hash = 2;
// IBC packet sequence
uint64 sequence = 3;
}
// MsgCancelOrder cancels an existing order
message MsgCancelOrder {
option (cosmos.msg.v1.signer) = "did";
option (gogoproto.goproto_getters) = false;
// DID canceling the order
string did = 1;
// IBC connection to DEX chain
string connection_id = 2;
// Order ID to cancel
string order_id = 3;
// UCAN authorization token
string ucan_token = 4;
}
// MsgCancelOrderResponse defines the response
message MsgCancelOrderResponse {
option (gogoproto.goproto_getters) = false;
// Transaction ID
string tx_hash = 1;
// IBC packet sequence
uint64 sequence = 2;
}
Regular → Executable
+1 -1
View File
@@ -7,5 +7,5 @@ import "cosmos/app/v1alpha1/module.proto";
// Module is the app config object of the module.
// Learn more: https://docs.cosmos.network/main/building-modules/depinject
message Module {
option (cosmos.app.v1alpha1.module) = {go_import: "github.com/sonr-io/snrd"};
option (cosmos.app.v1alpha1.module) = {go_import: "github.com/sonr-io/sonr"};
}
+90
View File
@@ -0,0 +1,90 @@
## Overview
Query endpoints for the DID module provide read access to decentralized identifiers, verifiable credentials, and identity metadata.
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Query Details
{{if eq .MethodDescriptorProto.Name "Params"}}
- Returns module parameters
- Includes WebAuthn configuration settings
- Shows supported signature algorithms
{{else if eq .MethodDescriptorProto.Name "ResolveDID"}}
- Resolves a DID to its complete document
- Returns verification methods and service endpoints
- Includes document metadata and version info
{{else if eq .MethodDescriptorProto.Name "GetDIDDocument"}}
- Retrieves a specific DID document by identifier
- Returns full W3C-compliant DID document
- Includes creation and update timestamps
{{else if eq .MethodDescriptorProto.Name "ListDIDDocuments"}}
- Lists all DID documents in the system
- Supports pagination for large result sets
- Returns documents in creation order
{{else if eq .MethodDescriptorProto.Name "GetDIDDocumentsByController"}}
- Finds all DIDs controlled by an address
- Useful for identity management interfaces
- Returns paginated results
{{else if eq .MethodDescriptorProto.Name "GetVerificationMethod"}}
- Retrieves specific verification method details
- Returns public key and algorithm information
- Shows associated verification relationships
{{else if eq .MethodDescriptorProto.Name "GetService"}}
- Gets specific service endpoint information
- Returns service type and endpoint URLs
- Includes service metadata
{{else if eq .MethodDescriptorProto.Name "GetVerifiableCredential"}}
- Retrieves a verifiable credential by ID
- Returns complete credential with proofs
- Shows issuance and expiration dates
{{else if eq .MethodDescriptorProto.Name "ListVerifiableCredentials"}}
- Lists verifiable credentials with filters
- Can filter by issuer or holder DID
- Optionally includes revoked credentials
{{else if eq .MethodDescriptorProto.Name "GetCredentialsByDID"}}
- Gets all credentials associated with a DID
- Includes both verifiable and WebAuthn credentials
- Shows vault storage status if applicable
{{end}}
## Usage Examples
```bash
# Query module parameters
snrd query did params
# Resolve a DID
snrd query did resolve did:sonr:123abc
# Get DID document
snrd query did document did:sonr:123abc
# List DIDs by controller
snrd query did documents-by-controller sonr1abc...
# Get verification method
snrd query did verification-method did:sonr:123abc key-1
# Query verifiable credential
snrd query did credential cred-123
# List credentials for a DID
snrd query did credentials-by-did did:sonr:123abc
```
## Response Formats
All responses follow W3C standards:
- DID Documents conform to W3C DID Core v1.0
- Verifiable Credentials follow W3C VC Data Model v1.1
- WebAuthn credentials comply with WebAuthn Level 2
+84
View File
@@ -0,0 +1,84 @@
## Overview
The DID module implements W3C Decentralized Identifiers (DIDs) with support for WebAuthn, verifiable credentials, and external wallet linking.
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Implementation Details
{{if eq .MethodDescriptorProto.Name "CreateDID"}}
- Creates a new W3C-compliant DID document
- Automatically generates unique DID identifier
- Can optionally create an associated vault for secure storage
- Supports multiple verification methods and service endpoints
{{else if eq .MethodDescriptorProto.Name "UpdateDID"}}
- Updates an existing DID document
- Maintains version history for auditability
- Only controller can perform updates
- Preserves immutable fields like creation timestamp
{{else if eq .MethodDescriptorProto.Name "DeactivateDID"}}
- Permanently deactivates a DID document
- Cannot be reversed once deactivated
- Maintains deactivated state for historical reference
- Revokes all associated credentials
{{else if eq .MethodDescriptorProto.Name "AddVerificationMethod"}}
- Adds new cryptographic verification methods
- Supports Ed25519, ECDSA, RSA, and WebAuthn
- Can specify verification relationships (authentication, assertion, etc.)
- Enables multi-signature capabilities
{{else if eq .MethodDescriptorProto.Name "RemoveVerificationMethod"}}
- Removes verification methods from DID document
- Cannot remove the last remaining verification method
- Updates all related verification relationships
{{else if eq .MethodDescriptorProto.Name "AddService"}}
- Adds service endpoints to DID document
- Enables discovery of services associated with DID
- Supports multiple service types and endpoints
{{else if eq .MethodDescriptorProto.Name "RemoveService"}}
- Removes service endpoints from DID document
- Cleans up service discovery metadata
{{else if eq .MethodDescriptorProto.Name "IssueVerifiableCredential"}}
- Issues W3C Verifiable Credentials
- Cryptographically signed by issuer's DID
- Supports custom credential schemas
- Includes issuance and expiration dates
{{else if eq .MethodDescriptorProto.Name "RevokeVerifiableCredential"}}
- Revokes previously issued credentials
- Maintains revocation registry on-chain
- Includes revocation reason for audit trail
{{else if eq .MethodDescriptorProto.Name "LinkExternalWallet"}}
- Links external blockchain wallets to DID
- Requires cryptographic proof of wallet ownership
- Supports Ethereum, Cosmos, and other chains
- Enables cross-chain identity bridging
{{else if eq .MethodDescriptorProto.Name "RegisterWebAuthnCredential"}}
- Registers WebAuthn credentials for passwordless authentication
- Creates new DID with WebAuthn as primary verification method
- Supports gasless onboarding for new users
- Can automatically create associated vault
- Enables biometric authentication (Face ID, Touch ID, etc.)
{{end}}
## Security Considerations
- All DID operations require controller authorization
- Cryptographic signatures validate all changes
- WebAuthn provides phishing-resistant authentication
- External wallet linking requires ownership proofs
- Verifiable credentials include tamper-evident signatures
## Standards Compliance
- W3C DID Core Specification v1.0
- W3C Verifiable Credentials Data Model v1.1
- WebAuthn Level 2 Specification
- DID Method Specification: did:sonr
+191
View File
@@ -0,0 +1,191 @@
syntax = "proto3";
package did.v1;
option go_package = "github.com/sonr-io/sonr/x/did/types";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
// EventDIDCreated is emitted when a new DID is created
message EventDIDCreated {
// DID identifier
string did = 1;
// Creator address
string creator = 2;
// Public keys added
repeated string public_keys = 3;
// Services added
repeated string services = 4;
// Creation timestamp
google.protobuf.Timestamp created_at = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 6;
}
// EventDIDUpdated is emitted when a DID is updated
message EventDIDUpdated {
// DID identifier
string did = 1;
// Updater address
string updater = 2;
// Fields that were updated
repeated string fields_updated = 3;
// Update timestamp
google.protobuf.Timestamp updated_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 5;
}
// EventDIDDeactivated is emitted when a DID is deactivated
message EventDIDDeactivated {
// DID identifier
string did = 1;
// Deactivator address
string deactivator = 2;
// Deactivation timestamp
google.protobuf.Timestamp deactivated_at = 3 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 4;
}
// EventVerificationMethodAdded is emitted when a verification method is added
message EventVerificationMethodAdded {
// DID identifier
string did = 1;
// Method ID
string method_id = 2;
// Key type
string key_type = 3;
// Public key (encoded)
string public_key = 4;
// Block height
uint64 block_height = 5;
}
// EventVerificationMethodRemoved is emitted when a verification method is removed
message EventVerificationMethodRemoved {
// DID identifier
string did = 1;
// Method ID
string method_id = 2;
// Block height
uint64 block_height = 3;
}
// EventServiceAdded is emitted when a service is added to a DID
message EventServiceAdded {
// DID identifier
string did = 1;
// Service ID
string service_id = 2;
// Service type
string type = 3;
// Service endpoint
string endpoint = 4;
// Block height
uint64 block_height = 5;
}
// EventServiceRemoved is emitted when a service is removed from a DID
message EventServiceRemoved {
// DID identifier
string did = 1;
// Service ID
string service_id = 2;
// Block height
uint64 block_height = 3;
}
// EventCredentialIssued is emitted when a verifiable credential is issued
message EventCredentialIssued {
// Credential ID
string credential_id = 1;
// Issuer DID
string issuer = 2;
// Subject DID
string subject = 3;
// Credential type
string type = 4;
// Issuance timestamp
google.protobuf.Timestamp issued_at = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 6;
}
// EventCredentialRevoked is emitted when a credential is revoked
message EventCredentialRevoked {
// Credential ID
string credential_id = 1;
// Revoker DID
string revoker = 2;
// Revocation reason
string reason = 3;
// Revocation timestamp
google.protobuf.Timestamp revoked_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 5;
}
// EventWebAuthnRegistered is emitted when a WebAuthn credential is registered
message EventWebAuthnRegistered {
// DID identifier
string did = 1;
// WebAuthn credential ID
string credential_id = 2;
// Attestation type
string attestation_type = 3;
// Block height
uint64 block_height = 4;
}
// EventExternalWalletLinked is emitted when an external wallet is linked
message EventExternalWalletLinked {
// DID identifier
string did = 1;
// Wallet type (ethereum, bitcoin, etc.)
string wallet_type = 2;
// Wallet address
string wallet_address = 3;
// Block height
uint64 block_height = 4;
}
+69 -29
View File
@@ -4,12 +4,15 @@ package did.v1;
import "amino/amino.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/snrd/x/did/types";
option go_package = "github.com/sonr-io/sonr/x/did/types";
// GenesisState defines the module genesis state
message GenesisState {
// Params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
// Export format version for future migrations
uint32 export_version = 2;
}
// Params defines the set of module parameters.
@@ -18,37 +21,74 @@ message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
repeated Attenuation attenuations = 1;
DocumentParams document = 1;
WebauthnParams webauthn = 2;
}
// Attenuation defines the attenuation of a resource
message Attenuation {
Resource resource = 1;
repeated Capability capabilities = 2;
// DocumentParams defines the parameters for the DID module.
message DocumentParams {
option (gogoproto.equal) = true;
// AutoCreateVault enables automatic vault creation upon DID registration
bool auto_create_vault = 1;
// MaxVerificationMethods limits the number of verification methods
int32 max_verification_methods = 2;
// MaxServiceEndpoints limits the number of service endpoints
int32 max_service_endpoints = 3;
// MaxControllers limits the number of controllers per DID document
int32 max_controllers = 4;
// DidDocumentMaxSize limits the maximum size of a DID document in bytes
int64 did_document_max_size = 5;
// DidResolutionTimeout is the timeout for resolution operations in seconds
int64 did_resolution_timeout = 6;
// KeyRotationInterval is the recommended interval for key rotation in seconds
int64 key_rotation_interval = 7;
// CredentialLifetime is the default lifetime in seconds
int64 credential_lifetime = 8;
// Supported Assertion methods
repeated string supported_assertion_methods = 9;
// Supported Authentication methods
repeated string supported_authentication_methods = 10;
// Supported Invocation methods
repeated string supported_invocation_methods = 11;
// Supported Delegation methods
repeated string supported_delegation_methods = 12;
}
// Capability reprensents the available capabilities of a decentralized web node
message Capability {
string name = 1;
string parent = 2;
string description = 3;
repeated string resources = 4;
// WebauthnParams defines the parameters for the WebAuthn module.
message WebauthnParams {
option (gogoproto.equal) = true;
// ChallengeTimeout is the default timeout in seconds
int64 challenge_timeout = 1;
// AllowedOrigins are the allowed WebAuthn origins for credential creation
repeated string allowed_origins = 2;
// SupportedAlgorithms are the supported signature for WebAuthn credentials
repeated string supported_algorithms = 3;
// RequireUserVerification enforces verification for WebAuthn credentials
bool require_user_verification = 4;
// MaxCredentialsPerDID limits the number of WebAuthn credentials per DID
int32 max_credentials_per_did = 5;
// DefaultRPID is the default Relying Party ID for WebAuthn operations
string default_rp_id = 6;
// DefaultRPName is the default Relying Party name for WebAuthn operations
string default_rp_name = 7;
}
// Resource reprensents the available resources of a decentralized web node
message Resource {
string kind = 1;
string template = 2;
}
// Document defines a DID document
message Document {
string id = 1;
string controller = 2; // The DID of the controller
repeated string authentication = 3;
repeated string assertion_method = 4;
repeated string capability_delegation = 5;
repeated string capability_invocation = 6;
repeated string service = 7;
}
+286 -43
View File
@@ -1,36 +1,86 @@
syntax = "proto3";
package did.v1;
import "cosmos/base/query/v1beta1/pagination.proto";
import "did/v1/genesis.proto";
import "google/api/annotations.proto";
import "did/v1/state.proto";
import "did/v1/types.proto";
option go_package = "github.com/sonr-io/snrd/x/did/types";
import "google/api/annotations.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/sonr/x/did/types";
// Query provides defines the gRPC querier service.
service Query {
// Params queries all parameters of the module.
rpc Params(QueryRequest) returns (QueryParamsResponse) {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/did/v1/params";
}
// Resolve queries the DID document by its id.
rpc Resolve(QueryRequest) returns (QueryResolveResponse) {
option (google.api.http).get = "/did/v1/{did}";
// ResolveDID resolves a DID to its DID document
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "did_query_docs.md"}}
rpc ResolveDID(QueryResolveDIDRequest) returns (QueryResolveDIDResponse) {
option (google.api.http).get = "/did/v1/resolve/{did}";
}
// Verify verifies a message with the DID document
rpc Verify(QueryVerifyRequest) returns (QueryVerifyResponse) {
option (google.api.http).post = "/did/v1/{did}/verify";
// GetDIDDocument retrieves a DID document by its ID
rpc GetDIDDocument(QueryGetDIDDocumentRequest) returns (QueryGetDIDDocumentResponse) {
option (google.api.http).get = "/did/v1/document/{did}";
}
// ListDIDDocuments lists all DID documents with pagination
rpc ListDIDDocuments(QueryListDIDDocumentsRequest) returns (QueryListDIDDocumentsResponse) {
option (google.api.http).get = "/did/v1/documents";
}
// GetDIDDocumentsByController retrieves DID documents by controller
rpc GetDIDDocumentsByController(QueryGetDIDDocumentsByControllerRequest) returns (QueryGetDIDDocumentsByControllerResponse) {
option (google.api.http).get = "/did/v1/documents/controller/{controller}";
}
// GetVerificationMethod retrieves a specific verification method
rpc GetVerificationMethod(QueryGetVerificationMethodRequest) returns (QueryGetVerificationMethodResponse) {
option (google.api.http).get = "/did/v1/verification-method/{did}/{method_id}";
}
// GetService retrieves a specific service endpoint
rpc GetService(QueryGetServiceRequest) returns (QueryGetServiceResponse) {
option (google.api.http).get = "/did/v1/service/{did}/{service_id}";
}
// GetVerifiableCredential retrieves a verifiable credential by ID
rpc GetVerifiableCredential(QueryGetVerifiableCredentialRequest) returns (QueryGetVerifiableCredentialResponse) {
option (google.api.http).get = "/did/v1/credential/{credential_id}";
}
// ListVerifiableCredentials lists all verifiable credentials with filtering options
rpc ListVerifiableCredentials(QueryListVerifiableCredentialsRequest) returns (QueryListVerifiableCredentialsResponse) {
option (google.api.http).get = "/did/v1/credentials";
}
// GetCredentialsByDID retrieves all credentials (verifiable and WebAuthn) associated with a DID
rpc GetCredentialsByDID(QueryGetCredentialsByDIDRequest) returns (QueryGetCredentialsByDIDResponse) {
option (google.api.http).get = "/did/v1/credentials/did/{did}";
}
// RegisterStart represents the start of the registration process
rpc RegisterStart(QueryRegisterStartRequest) returns (QueryRegisterStartResponse) {
option (google.api.http).post = "/did/v1/register/start";
}
// LoginStart represents the start of the login process
rpc LoginStart(QueryLoginStartRequest) returns (QueryLoginStartResponse) {
option (google.api.http).post = "/did/v1/login/start";
}
}
// Queryequest is the request type for the Query/Params RPC method.
message QueryRequest {
string did = 1;
string origin = 2;
string key = 3;
string asset = 4;
}
// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
@@ -38,39 +88,232 @@ message QueryParamsResponse {
Params params = 1;
}
// QueryResolveResponse is the response type for the Query/Resolve RPC method.
message QueryResolveResponse {
// document is the DID document
Document document = 1;
}
// QuerySignRequest is the request type for the Query/Sign RPC method.
message QuerySignRequest {
// QueryResolveDIDRequest is the request type for the Query/ResolveDID RPC
// method.
message QueryResolveDIDRequest {
// did is the DID to resolve
string did = 1;
string origin = 2;
string key = 3;
string asset = 4;
string message = 5;
}
// QuerySignResponse is the response type for the Query/Sign RPC method.
message QuerySignResponse {
// signature is the signature of the message
string signature = 1;
// QueryResolveDIDResponse is the response type for the Query/ResolveDID RPC
// method.
message QueryResolveDIDResponse {
// did_document is the resolved DID document
DIDDocument did_document = 1;
// did_document_metadata contains metadata about the DID document
DIDDocumentMetadata did_document_metadata = 2;
}
// QueryVerifyRequest is the request type for the Query/Verify RPC method.
message QueryVerifyRequest {
// QueryGetDIDDocumentRequest is the request type for the
// Query/GetDIDDocument RPC method.
message QueryGetDIDDocumentRequest {
// did is the DID to retrieve
string did = 1;
string origin = 2;
string key = 3;
string asset = 4;
string message = 5;
string signature = 6;
}
// QueryVerifyResponse is the response type for the Query/Verify RPC method.
message QueryVerifyResponse {
// valid is the validity of the signature
bool valid = 1;
// QueryGetDIDDocumentResponse is the response type for the
// Query/GetDIDDocument RPC method.
message QueryGetDIDDocumentResponse {
// did_document is the retrieved DID document
DIDDocument did_document = 1;
// did_document_metadata contains metadata about the DID document
DIDDocumentMetadata did_document_metadata = 2;
}
// QueryListDIDDocumentsRequest is the request type for the
// Query/ListDIDDocuments RPC method.
message QueryListDIDDocumentsRequest {
// pagination defines an optional pagination for the request
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}
// QueryListDIDDocumentsResponse is the response type for the
// Query/ListDIDDocuments RPC method.
message QueryListDIDDocumentsResponse {
// did_documents is the list of DID documents
repeated DIDDocument did_documents = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetDIDDocumentsByControllerRequest is the request type for the
// Query/GetDIDDocumentsByController RPC method.
message QueryGetDIDDocumentsByControllerRequest {
// controller is the controller to search for
string controller = 1;
// pagination defines an optional pagination for the request
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryGetDIDDocumentsByControllerResponse is the response type for the
// Query/GetDIDDocumentsByController RPC method.
message QueryGetDIDDocumentsByControllerResponse {
// did_documents is the list of DID documents controlled by the controller
repeated DIDDocument did_documents = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetVerificationMethodRequest is the request type for the
// Query/GetVerificationMethod RPC method.
message QueryGetVerificationMethodRequest {
// did is the DID that contains the verification method
string did = 1;
// method_id is the ID of the verification method
string method_id = 2;
}
// QueryGetVerificationMethodResponse is the response type for the
// Query/GetVerificationMethod RPC method.
message QueryGetVerificationMethodResponse {
// verification_method is the retrieved verification method
VerificationMethod verification_method = 1;
}
// QueryGetServiceRequest is the request type for the Query/GetService RPC
// method.
message QueryGetServiceRequest {
// did is the DID that contains the service
string did = 1;
// service_id is the ID of the service
string service_id = 2;
}
// QueryGetServiceResponse is the response type for the Query/GetService
// RPC method.
message QueryGetServiceResponse {
// service is the retrieved service
Service service = 1;
}
// QueryGetVerifiableCredentialRequest is the request type for the
// Query/GetVerifiableCredential RPC method.
message QueryGetVerifiableCredentialRequest {
// credential_id is the ID of the credential to retrieve
string credential_id = 1;
}
// QueryGetVerifiableCredentialResponse is the response type for the
// Query/GetVerifiableCredential RPC method.
message QueryGetVerifiableCredentialResponse {
// credential is the retrieved verifiable credential
VerifiableCredential credential = 1;
}
// QueryListVerifiableCredentialsRequest is the request type for the
// Query/ListVerifiableCredentials RPC method.
message QueryListVerifiableCredentialsRequest {
// pagination defines an optional pagination for the request
cosmos.base.query.v1beta1.PageRequest pagination = 1;
// issuer filters by issuer DID (optional)
string issuer = 2;
// holder filters by holder DID (optional)
string holder = 3;
// include_revoked includes revoked credentials (default: false)
bool include_revoked = 4;
}
// QueryListVerifiableCredentialsResponse is the response type for the
// Query/ListVerifiableCredentials RPC method.
message QueryListVerifiableCredentialsResponse {
// credentials is the list of verifiable credentials
repeated VerifiableCredential credentials = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// CredentialInfo wraps credential data with vault status
message CredentialInfo {
// credential can be either verifiable or WebAuthn
oneof credential {
VerifiableCredential verifiable_credential = 1;
WebAuthnCredential webauthn_credential = 2;
}
// vault_id indicates if stored in vault (empty if not)
string vault_id = 3;
// is_encrypted indicates if encrypted in vault
bool is_encrypted = 4;
}
// QueryGetCredentialsByDIDRequest is the request type for the
// Query/GetCredentialsByDID RPC method.
message QueryGetCredentialsByDIDRequest {
// did is the DID to retrieve all credentials for
string did = 1;
// include_verifiable includes verifiable credentials (default: true)
bool include_verifiable = 2;
// include_webauthn includes WebAuthn credentials (default: true)
bool include_webauthn = 3;
// include_revoked includes revoked credentials (default: false)
bool include_revoked = 4;
// pagination defines an optional pagination for the request
cosmos.base.query.v1beta1.PageRequest pagination = 5;
}
// QueryGetCredentialsByDIDResponse is the response type for the
// Query/GetCredentialsByDID RPC method.
message QueryGetCredentialsByDIDResponse {
// credentials is the list of all credentials associated with the DID
repeated CredentialInfo credentials = 1;
// pagination defines the pagination in the response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryRegisterStartRequest is the request type for the
// Query/RegisterStart RPC method.
message QueryRegisterStartRequest {
// assertion_did is the DID to register (did:sonr:email:<blake3> or did:sonr:phone:<blake3>)
string assertion_did = 1;
}
// QueryRegisterStartResponse is the response type for the
// Query/RegisterStart RPC method.
message QueryRegisterStartResponse {
// challenge for the attestation ceremony (32 bytes)
bytes challenge = 1;
// relying_party_id identifier
string relying_party_id = 2;
// user information (id, name, displayName)
map<string, string> user = 3;
}
// QueryLoginStartRequest is the request type for the
// Query/LoginStart RPC method.
message QueryLoginStartRequest {
// assertion_did is the assertion DID (did:sonr:email:<blake3> or did:sonr:phone:<blake3>)
string assertion_did = 1;
}
// QueryLoginStartResponse is the response type for the
// Query/LoginStart RPC method.
message QueryLoginStartResponse {
// credential_ids associated with this assertion
repeated string credential_ids = 1;
// challenge for the assertion ceremony (32 bytes)
bytes challenge = 2;
// relying_party_id identifier
string relying_party_id = 3;
}
+293 -71
View File
@@ -4,10 +4,12 @@ package did.v1;
import "cosmos/orm/v1/orm.proto";
import "did/v1/genesis.proto";
import "did/v1/types.proto";
option go_package = "github.com/sonr-io/snrd/x/did/types";
option go_package = "github.com/sonr-io/sonr/x/did/types";
message Account {
// Authentication is the authentication method to be used by the DID.
message Authentication {
option (cosmos.orm.v1.table) = {
id: 1
primary_key: {fields: "did"}
@@ -28,122 +30,342 @@ message Account {
string subject = 3;
// string is the verification method
string public_key_hex = 4;
string public_key_base64 = 4;
// AssertionType is the assertion type
string assertion_type = 5;
// Metadata of the authentication
map<string, bytes> accumulator = 6;
// AssertionKind is the assertion type
string did_kind = 5;
// CreationBlock is the block number of the creation of the authentication
int64 creation_block = 7;
int64 creation_block = 6;
}
// PublicKey represents a public key
message PublicKey {
// Assertion is the assertion method to be used by the DID.
message Assertion {
option (cosmos.orm.v1.table) = {
id: 2
primary_key: {
fields: "number"
auto_increment: true
}
primary_key: {fields: "did"}
index: {
id: 1
fields: "sonr_address"
unique: true
}
index: {
id: 2
fields: "eth_address"
unique: true
}
index: {
id: 3
fields: "btc_address"
unique: true
}
index: {
id: 4
fields: "did"
fields: "controller,subject"
unique: true
}
};
// The unique identifier of the controller
uint64 number = 1;
// The unique identifier of the assertion
string did = 1;
// The unique identifier of the controller
string did = 2;
// The authentication of the DID
string controller = 2;
// The DID of the controller
string sonr_address = 3;
// The DID of the controller
string eth_address = 4;
// The DID of the controller
string btc_address = 5;
// Origin of the authentication
string subject = 3;
// string is the verification method
string public_key_hex = 6;
string public_key_base64 = 4;
// Pointer to the Keyshares
string ks_val = 7;
// DIDKind is the DID type
string did_kind = 5;
// The block number of when a user claimed the controller
int64 claimed_block = 8;
// CreationBlock is the block number of the creation of the controller
int64 creation_block = 9;
// CreationBlock is the block number of the creation of the authentication
int64 creation_block = 6;
}
// Verification represents a verification method
message Verification {
// Controller is the controller method to be used by the DID.
message Controller {
option (cosmos.orm.v1.table) = {
id: 3
primary_key: {fields: "did"}
index: {
id: 1
fields: "issuer,subject"
fields: "address"
unique: true
}
index: {
id: 2
fields: "controller,did_method,issuer"
fields: "subject"
unique: true
}
index: {
id: 3
fields: "verification_type,subject,issuer"
fields: "public_key_base64"
unique: true
}
};
// The unique identifier of the verification
// The unique identifier of the assertion
string did = 1;
// The controller of the verification
// The authentication of the DID
string address = 2;
// Origin of the authentication
string subject = 3;
// string is the verification method
string public_key_base64 = 4;
// DIDKind is the DID type
string did_kind = 5;
// CreationBlock is the block number of the creation of the authentication
int64 creation_block = 6;
}
// Delegation is usually an external blockchain account that is used to sign
// transactions on behalf of the DID
message Delegation {
option (cosmos.orm.v1.table) = {
id: 4
primary_key: {fields: "did"}
index: {
id: 1
fields: "controller,subject"
unique: true
}
};
// The unique identifier of the assertion
string did = 1;
// The authentication of the DID
string controller = 2;
// The DIDNamespace of the verification
string did_method = 3;
// Origin of the authentication
string subject = 3;
// The value of the linked identifier
// string is the verification method
string public_key_base64 = 4;
// DIDKind is the DID type
string did_kind = 5;
// CreationBlock is the block number of the creation of the authentication
int64 creation_block = 6;
}
// Invocation is usually a smart contract that is used to sign transactions on
// behalf of the DID
message Invocation {
option (cosmos.orm.v1.table) = {
id: 5
primary_key: {fields: "did"}
index: {
id: 1
fields: "controller,subject"
unique: true
}
};
// The unique identifier of the assertion
string did = 1;
// The authentication of the DID
string controller = 2;
// Origin of the authentication
string subject = 3;
// string is the verification method
string public_key_base64 = 4;
// DIDKind is the DID type
string did_kind = 5;
// CreationBlock is the block number of the creation of the authentication
int64 creation_block = 6;
}
// DIDDocument represents a W3C compliant DID Document
message DIDDocument {
option (cosmos.orm.v1.table) = {
id: 6
primary_key: {fields: "id"}
index: {
id: 1
fields: "primary_controller"
unique: false
}
};
// id is the DID that is the subject of this DID Document (REQUIRED)
string id = 1;
// primary_controller identifies the primary entity that controls the DID
// document (OPTIONAL)
string primary_controller = 2;
// alsoKnownAs expresses other identifiers for the DID subject (OPTIONAL)
repeated string also_known_as = 3;
// verificationMethod expresses verification methods (OPTIONAL)
repeated VerificationMethod verification_method = 4;
// authentication expresses authentication verification relationships
// (OPTIONAL)
repeated VerificationMethodReference authentication = 5;
// assertionMethod expresses assertion verification relationships (OPTIONAL)
repeated VerificationMethodReference assertion_method = 6;
// keyAgreement expresses key agreement verification relationships (OPTIONAL)
repeated VerificationMethodReference key_agreement = 7;
// capabilityInvocation expresses capability invocation verification
// relationships (OPTIONAL)
repeated VerificationMethodReference capability_invocation = 8;
// capabilityDelegation expresses capability delegation verification
// relationships (OPTIONAL)
repeated VerificationMethodReference capability_delegation = 9;
// service expresses service endpoints (OPTIONAL)
repeated Service service = 10;
// Block height when the DID document was created
int64 created_at = 11;
// Block height when the DID document was last updated
int64 updated_at = 12;
// Whether the DID document is deactivated
bool deactivated = 13;
// Version number for the DID document
uint64 version = 14;
}
// DIDDocumentMetadata contains metadata about the DID document
message DIDDocumentMetadata {
option (cosmos.orm.v1.table) = {
id: 7
primary_key: {fields: "did"}
};
// did is the DID this metadata belongs to
string did = 1;
// created is when the DID was created
int64 created = 2;
// updated is when the DID was last updated
int64 updated = 3;
// deactivated is when the DID was deactivated (if applicable)
int64 deactivated = 4;
// version_id is the version identifier
string version_id = 5;
// next_update is when the next update is scheduled (if applicable)
int64 next_update = 6;
// next_version_id is the next version identifier (if applicable)
string next_version_id = 7;
// equivalentId lists equivalent DIDs
repeated string equivalent_id = 8;
// canonicalId is the canonical DID
string canonical_id = 9;
}
// VerifiableCredential represents a W3C Verifiable Credential
message VerifiableCredential {
option (cosmos.orm.v1.table) = {
id: 8
primary_key: {fields: "id"}
index: {
id: 1
fields: "issuer"
unique: false
}
index: {
id: 2
fields: "subject"
unique: false
}
index: {
id: 3
fields: "issuer,subject"
unique: true
}
};
// id is the credential identifier
string id = 1;
// context is the JSON-LD contexts
repeated string context = 2;
// credential_kinds is the credential types
repeated string credential_kinds = 3;
// issuer is the DID of the credential issuer
string issuer = 4;
// The subject of the verification
string subject = 5;
// issuanceDate is when the credential was issued
string issuance_date = 5;
// The public key of the verification
string public_key_hex = 6;
// expirationDate is when the credential expires (optional)
string expiration_date = 6;
// The verification method type
string verification_type = 7;
// credentialSubject contains the claims about the subject as JSON
bytes credential_subject = 7;
// Metadata of the verification
map<string, string> metadata = 8;
// proof contains the cryptographic proof
repeated CredentialProof proof = 8;
// CreationBlock is the block number of the creation of the controller
int64 creation_block = 9;
// credentialStatus contains information about credential revocation
// (optional)
CredentialStatus credential_status = 9;
// subject is the DID of the credential subject (for indexing)
string subject = 10;
// Block height when issued
int64 issued_at = 11;
// Block height when expires (0 if no expiration)
int64 expires_at = 12;
// Whether the credential is revoked
bool revoked = 13;
}
// DIDController represents additional controllers for a DID document
message DIDController {
option (cosmos.orm.v1.table) = {
id: 9
primary_key: {
fields: "id"
auto_increment: true
}
index: {
id: 1
fields: "did"
unique: true
}
index: {
id: 2
fields: "controller_did"
unique: true
}
index: {
id: 3
fields: "did,controller_did"
unique: true
}
};
// id is the auto-incrementing primary key
uint64 id = 1;
// did is the DID this controller belongs to
string did = 2;
// controller_did is the controller DID
string controller_did = 3;
// added_at is when this controller was added
int64 added_at = 4;
}
+283 -139
View File
@@ -1,165 +1,71 @@
syntax = "proto3";
package did.v1;
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "did/v1/genesis.proto";
import "did/v1/state.proto";
import "did/v1/types.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/snrd/x/did/types";
option go_package = "github.com/sonr-io/sonr/x/did/types";
// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// ExecuteTx executes a transaction on the Sonr Blockchain. It leverages
// Macaroon for verification.
rpc ExecuteTx(MsgExecuteTx) returns (MsgExecuteTxResponse);
// LinkAssertion links an assertion to a controller.
rpc LinkAssertion(MsgLinkAssertion) returns (MsgLinkAssertionResponse);
// LinkAuthentication links an authentication to a controller.
rpc LinkAuthentication(MsgLinkAuthentication) returns (MsgLinkAuthenticationResponse);
// UnlinkAssertion unlinks an assertion from a controller.
rpc UnlinkAssertion(MsgUnlinkAssertion) returns (MsgUnlinkAssertionResponse);
// UnlinkAuthentication unlinks an authentication from a controller.
rpc UnlinkAuthentication(MsgUnlinkAuthentication) returns (MsgUnlinkAuthenticationResponse);
// UpdateParams defines a governance operation for updating the parameters.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}
// MsgLinkAuthentication is the message type for the LinkAuthentication RPC.
message MsgLinkAuthentication {
option (cosmos.msg.v1.signer) = "controller";
// CreateDID creates a new DID document
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "did_tx_docs.md"}}
rpc CreateDID(MsgCreateDID) returns (MsgCreateDIDResponse);
// Controller is the address of the controller to authenticate.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// UpdateDID updates an existing DID document
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "did_tx_docs.md"}}
rpc UpdateDID(MsgUpdateDID) returns (MsgUpdateDIDResponse);
// Subject is the subject of the authentication.
string subject = 2;
// DeactivateDID deactivates a DID document
rpc DeactivateDID(MsgDeactivateDID) returns (MsgDeactivateDIDResponse);
// Assertion is the assertion of the authentication.
string assertion = 3;
// AddVerificationMethod adds a new verification method to a DID document
rpc AddVerificationMethod(MsgAddVerificationMethod) returns (MsgAddVerificationMethodResponse);
// Authentication is the authentication of the authentication.
bytes credential_id = 4;
// RemoveVerificationMethod removes a verification method from a DID document
rpc RemoveVerificationMethod(MsgRemoveVerificationMethod) returns (MsgRemoveVerificationMethodResponse);
// token is the macron token to authenticate the operation.
string macaroon_token = 5;
}
// AddService adds a new service endpoint to a DID document
rpc AddService(MsgAddService) returns (MsgAddServiceResponse);
// MsgLinkAuthenticationResponse is the response type for the
// LinkAuthentication RPC.
message MsgLinkAuthenticationResponse {
// Success returns true if the specified cid is valid and not already
// encrypted.
bool success = 1;
// RemoveService removes a service endpoint from a DID document
rpc RemoveService(MsgRemoveService) returns (MsgRemoveServiceResponse);
// Controller is the address of the initialized controller.
string did = 2;
}
// IssueVerifiableCredential issues a new verifiable credential
rpc IssueVerifiableCredential(MsgIssueVerifiableCredential) returns (MsgIssueVerifiableCredentialResponse);
// MsgLinkAssertion is the message type for the LinkAssertion RPC.
message MsgLinkAssertion {
option (cosmos.msg.v1.signer) = "controller";
// RevokeVerifiableCredential revokes a verifiable credential
rpc RevokeVerifiableCredential(MsgRevokeVerifiableCredential) returns (MsgRevokeVerifiableCredentialResponse);
// Controller is the address of the controller to authenticate.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// LinkExternalWallet links an external wallet as an assertion method
rpc LinkExternalWallet(MsgLinkExternalWallet) returns (MsgLinkExternalWalletResponse);
// Subject is the subject of the authentication.
string subject = 2;
// Assertion is the assertion of the authentication.
string assertion = 3;
// token is the macron token to authenticate the operation.
string macaroon_token = 4;
}
// MsgLinkAssertionResponse is the response type for the
// LinkAssertion RPC.
message MsgLinkAssertionResponse {
// Success returns true if the specified cid is valid and not already
// encrypted.
bool success = 1;
// Controller is the address of the initialized controller.
string did = 2;
}
// MsgExecuteTx is the message type for the ExecuteTx RPC.
message MsgExecuteTx {
option (cosmos.msg.v1.signer) = "controller";
// Controller is the address of the controller to authenticate.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Messages is the list of messages to execute.
map<string, bytes> messages = 2;
// MacaroonToken is the macaroon token to authenticate the operation.
string macaroon_token = 3;
}
// MsgExecuteTxResponse is the response type for the ExecuteTx RPC.
message MsgExecuteTxResponse {
bool success = 1;
string tx_hash = 2;
}
// MsgUnlinkAssertion is the message type for the UnlinkAssertion RPC.
message MsgUnlinkAssertion {
option (cosmos.msg.v1.signer) = "controller";
// Controller is the address of the controller to authenticate.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Assertion is the assertion of the authentication.
string assertion_did = 2;
// token is the macron token to authenticate the operation.
string macaroon_token = 3;
}
// MsgUnlinkAssertionResponse is the response type for the
// UnlinkAssertion RPC.
message MsgUnlinkAssertionResponse {
// Success returns true if the specified cid is valid and not already
// encrypted.
bool success = 1;
// Controller is the address of the initialized controller.
string did = 2;
}
// MsgUnlinkAuthentication is the message type for the UnlinkAuthentication RPC.
message MsgUnlinkAuthentication {
option (cosmos.msg.v1.signer) = "controller";
// Controller is the address of the controller to authenticate.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Subject is the subject of the authentication.
string authentication_did = 2;
// token is the macron token to authenticate the operation.
string macaroon_token = 3;
}
// MsgUnlinkAuthenticationResponse is the response type for the
// UnlinkAuthentication RPC.
message MsgUnlinkAuthenticationResponse {
// Success returns true if the specified cid is valid and not already
// encrypted.
bool success = 1;
// Controller is the address of the initialized controller.
string did = 2;
// RegisterWebAuthnCredential registers a new WebAuthn credential and creates a DID
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "did_tx_docs.md"}}
rpc RegisterWebAuthnCredential(MsgRegisterWebAuthnCredential) returns (MsgRegisterWebAuthnCredentialResponse);
}
// MsgUpdateParams is the Msg/UpdateParams request type.
@@ -172,10 +78,9 @@ message MsgUpdateParams {
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// params defines the parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
// token is the macron token to authenticate the operation.
string token = 3;
}
// MsgUpdateParamsResponse defines the response structure for executing a
@@ -183,3 +88,242 @@ message MsgUpdateParams {
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
// MsgCreateDID creates a new DID document
message MsgCreateDID {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address creating the DID
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did_document is the DID document to create
DIDDocument did_document = 2 [(gogoproto.nullable) = false];
}
// MsgCreateDIDResponse defines the response for MsgCreateDID
message MsgCreateDIDResponse {
// did is the created DID identifier
string did = 1;
// vault_id is the ID of the auto-created vault (optional)
string vault_id = 2;
// vault_public_key is the public key of the auto-created vault (optional)
bytes vault_public_key = 3;
// enclave_id is the enclave ID of the auto-created vault (optional)
string enclave_id = 4;
}
// MsgUpdateDID updates an existing DID document
message MsgUpdateDID {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address updating the DID
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to update
string did = 2;
// did_document is the updated DID document
DIDDocument did_document = 3 [(gogoproto.nullable) = false];
}
// MsgUpdateDIDResponse defines the response for MsgUpdateDID
message MsgUpdateDIDResponse {}
// MsgDeactivateDID deactivates a DID document
message MsgDeactivateDID {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address deactivating the DID
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to deactivate
string did = 2;
}
// MsgDeactivateDIDResponse defines the response for MsgDeactivateDID
message MsgDeactivateDIDResponse {}
// MsgAddVerificationMethod adds a verification method to a DID document
message MsgAddVerificationMethod {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address adding the verification method
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to add the verification method to
string did = 2;
// verification_method is the verification method to add
VerificationMethod verification_method = 3 [(gogoproto.nullable) = false];
// relationships specifies which verification relationships to add
repeated string relationships = 4;
}
// MsgAddVerificationMethodResponse defines the response for
// MsgAddVerificationMethod
message MsgAddVerificationMethodResponse {}
// MsgRemoveVerificationMethod removes a verification method from a DID document
message MsgRemoveVerificationMethod {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address removing the verification method
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to remove the verification method from
string did = 2;
// verification_method_id is the ID of the verification method to remove
string verification_method_id = 3;
}
// MsgRemoveVerificationMethodResponse defines the response for
// MsgRemoveVerificationMethod
message MsgRemoveVerificationMethodResponse {}
// MsgAddService adds a service endpoint to a DID document
message MsgAddService {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address adding the service
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to add the service to
string did = 2;
// service is the service to add
Service service = 3 [(gogoproto.nullable) = false];
}
// MsgAddServiceResponse defines the response for MsgAddService
message MsgAddServiceResponse {}
// MsgRemoveService removes a service endpoint from a DID document
message MsgRemoveService {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address removing the service
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to remove the service from
string did = 2;
// service_id is the ID of the service to remove
string service_id = 3;
}
// MsgRemoveServiceResponse defines the response for MsgRemoveService
message MsgRemoveServiceResponse {}
// MsgIssueVerifiableCredential issues a new verifiable credential
message MsgIssueVerifiableCredential {
option (cosmos.msg.v1.signer) = "issuer";
// issuer is the address issuing the credential
string issuer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// credential is the verifiable credential to issue
VerifiableCredential credential = 2 [(gogoproto.nullable) = false];
}
// MsgIssueVerifiableCredentialResponse defines the response for
// MsgIssueVerifiableCredential
message MsgIssueVerifiableCredentialResponse {
// credential_id is the ID of the issued credential
string credential_id = 1;
}
// MsgRevokeVerifiableCredential revokes a verifiable credential
message MsgRevokeVerifiableCredential {
option (cosmos.msg.v1.signer) = "issuer";
// issuer is the address revoking the credential
string issuer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// credential_id is the ID of the credential to revoke
string credential_id = 2;
// revocation_reason is the reason for revocation
string revocation_reason = 3;
}
// MsgRevokeVerifiableCredentialResponse defines the response for
// MsgRevokeVerifiableCredential
message MsgRevokeVerifiableCredentialResponse {}
// MsgLinkExternalWallet links an external wallet to a DID as an assertion method
message MsgLinkExternalWallet {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address that controls the DID
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// did is the DID to link the wallet to
string did = 2;
// wallet_address is the external wallet address
string wallet_address = 3;
// chain_id identifies the blockchain (e.g., "1" for Ethereum mainnet, "cosmoshub-4")
string wallet_chain_id = 4;
// wallet_type specifies the wallet type ("ethereum", "cosmos")
string wallet_type = 5;
// ownership_proof is the signature proving ownership of the wallet
bytes ownership_proof = 6;
// challenge is the message that was signed to create the ownership_proof
bytes challenge = 7;
// verification_method_id is the ID for the new verification method
string verification_method_id = 8;
}
// MsgLinkExternalWalletResponse defines the response for MsgLinkExternalWallet
message MsgLinkExternalWalletResponse {
// verification_method_id is the ID of the created verification method
string verification_method_id = 1;
}
// MsgRegisterWebAuthnCredential registers a new WebAuthn credential and creates a DID
message MsgRegisterWebAuthnCredential {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address that will control the created DID
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// username is the human-readable identifier for the DID
string username = 2;
// webauthn_credential contains the WebAuthn credential data
WebAuthnCredential webauthn_credential = 3 [(gogoproto.nullable) = false];
// verification_method_id is the ID for the WebAuthn verification method
string verification_method_id = 4;
// auto_create_vault indicates whether to automatically create a vault
bool auto_create_vault = 5;
}
// MsgRegisterWebAuthnCredentialResponse defines the response for MsgRegisterWebAuthnCredential
message MsgRegisterWebAuthnCredentialResponse {
// did is the created DID identifier
string did = 1;
// verification_method_id is the ID of the created verification method
string verification_method_id = 2;
// vault_id is the ID of the auto-created vault (if requested)
string vault_id = 3;
// vault_public_key is the public key of the auto-created vault (if requested)
bytes vault_public_key = 4;
// enclave_id is the enclave ID of the auto-created vault (if requested)
string enclave_id = 5;
}
+161
View File
@@ -0,0 +1,161 @@
syntax = "proto3";
package did.v1;
import "amino/amino.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/sonr/x/did/types";
// VerificationMethod represents a verification method in a DID document
message VerificationMethod {
// id is the verification method identifier (REQUIRED)
string id = 1;
// verification_method_kind is the verification method type (REQUIRED)
string verification_method_kind = 2;
// controller is the DID that controls this verification method (REQUIRED)
string controller = 3;
// Public key material (optional, only one should be set)
// publicKeyJwk represents the public key as a JSON Web Key
string public_key_jwk = 4;
// publicKeyMultibase represents the public key as multibase
string public_key_multibase = 5;
// publicKeyBase58 represents the public key in Base58 (legacy)
string public_key_base58 = 6;
// publicKeyBase64 represents the public key in Base64 (legacy)
string public_key_base64 = 7;
// publicKeyPem represents the public key in PEM format (legacy)
string public_key_pem = 8;
// publicKeyHex represents the public key in hexadecimal (legacy)
string public_key_hex = 9;
// WebAuthn credential information (for WebAuthn integration)
WebAuthnCredential webauthn_credential = 10;
// blockchain_account_id for external wallet linking (CAIP-10 format)
// Format: "eip155:1:0x89a932207c485f85226d86f7cd486a89a24fcc12" for Ethereum
// Format: "cosmos:cosmoshub-4:cosmos1..." for Cosmos chains
string blockchain_account_id = 11;
}
// VerificationMethodReference can be either an embedded verification method
// or a reference
message VerificationMethodReference {
// verification_method_id is a reference to a verification method by ID (optional)
string verification_method_id = 1;
// embedded_verification_method is an embedded verification method (optional)
VerificationMethod embedded_verification_method = 2;
}
// Service represents a service endpoint in a DID document
message Service {
// id is the service identifier (REQUIRED)
string id = 1;
// service_kind is the service type (REQUIRED)
string service_kind = 2;
// single_endpoint for a single URL
string single_endpoint = 3;
// multiple_endpoints for multiple URLs
ServiceEndpoints multiple_endpoints = 4;
// complex_endpoint for complex endpoint objects as JSON
bytes complex_endpoint = 5;
// Additional properties for the service
map<string, string> properties = 6;
}
// ServiceEndpoints represents multiple service endpoints
message ServiceEndpoints {
repeated string endpoints = 1;
}
// WebAuthnCredential represents WebAuthn credential information
message WebAuthnCredential {
// credential_id is the WebAuthn credential ID
string credential_id = 1;
// public_key is the WebAuthn public key
bytes public_key = 2;
// algorithm is the signing algorithm
int32 algorithm = 3;
// attestation_type is the attestation type
string attestation_type = 4;
// origin is the origin where the credential was created
string origin = 5;
// created_at is when the credential was created
int64 created_at = 6;
// rp_id is the Relying Party ID
string rp_id = 7;
// rp_name is the Relying Party Name
string rp_name = 8;
// transports are the authenticator transports
repeated string transports = 9;
// user_verified indicates whether user verification was performed
bool user_verified = 10;
// signature_algorithm provides detailed algorithm information
string signature_algorithm = 11;
// raw_id is the base64url encoded raw credential ID
string raw_id = 12;
// client_data_json is the base64url encoded client data JSON
string client_data_json = 13;
// attestation_object is the base64url encoded attestation object
string attestation_object = 14;
}
// CredentialProof represents a cryptographic proof for a verifiable
// credential
message CredentialProof {
// proof_kind is the proof type
string proof_kind = 1;
// created is when the proof was created
string created = 2;
// verificationMethod is the verification method used
string verification_method = 3;
// proofPurpose is the purpose of the proof
string proof_purpose = 4;
// signature is the cryptographic signature
string signature = 5;
// Additional proof properties
map<string, string> properties = 6;
}
// CredentialStatus represents the revocation status of a credential
message CredentialStatus {
// id is the status identifier
string id = 1;
// status_kind is the status type
string status_kind = 2;
// Additional status properties
map<string, string> properties = 3;
}
Regular → Executable
+1 -3
View File
@@ -7,7 +7,5 @@ import "cosmos/app/v1alpha1/module.proto";
// Module is the app config object of the module.
// Learn more: https://docs.cosmos.network/main/building-modules/depinject
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import : "github.com/sonr-io/snrd"
};
option (cosmos.app.v1alpha1.module) = {go_import: "github.com/sonr-io/sonr"};
}
+70
View File
@@ -0,0 +1,70 @@
## Overview
The DWN (Decentralized Web Node) module provides decentralized data storage with encryption, permissions, and protocol management.
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Implementation Details
{{if eq .MethodDescriptorProto.Name "RecordsWrite"}}
- Creates or updates records in decentralized storage
- Supports encryption for sensitive data
- Stores data on IPFS with CID references
- Enables protocol-based data organization
{{else if eq .MethodDescriptorProto.Name "RecordsDelete"}}
- Removes records from DWN storage
- Can prune descendant records recursively
- Maintains deletion history for audit
{{else if eq .MethodDescriptorProto.Name "ProtocolsConfigure"}}
- Defines custom protocols for data organization
- Establishes schema and validation rules
- Enables structured data interactions
{{else if eq .MethodDescriptorProto.Name "PermissionsGrant"}}
- Grants access permissions to other DIDs
- Supports fine-grained access control
- Can scope permissions to specific protocols or records
{{else if eq .MethodDescriptorProto.Name "PermissionsRevoke"}}
- Revokes previously granted permissions
- Immediate effect on access control
{{else if eq .MethodDescriptorProto.Name "RotateVaultKeys"}}
- Rotates encryption keys for vaults
- Maintains data accessibility during rotation
- Supports scheduled and forced rotations
{{else if eq .MethodDescriptorProto.Name "Records"}}
- Queries records with flexible filters
- Supports filtering by protocol, schema, parent
- Returns paginated results
{{else if eq .MethodDescriptorProto.Name "Vault"}}
- Retrieves vault encryption status
- Shows key rotation history
- Returns vault metadata
{{else if eq .MethodDescriptorProto.Name "IPFS"}}
- Returns IPFS node status and connectivity
- Shows peer count and storage metrics
{{else if eq .MethodDescriptorProto.Name "CID"}}
- Retrieves data by IPFS Content Identifier
- Returns raw data from distributed storage
{{end}}
## Storage Architecture
- **IPFS Integration**: Large data stored on IPFS network
- **On-chain References**: Blockchain stores CIDs and metadata
- **Vault Encryption**: Sensitive data encrypted before storage
- **Protocol Organization**: Data structured by custom protocols
## Security Features
- End-to-end encryption for private data
- JWT-based authorization for operations
- Granular permission system
- Cryptographic attestations for data integrity
+155
View File
@@ -0,0 +1,155 @@
syntax = "proto3";
package dwn.v1;
option go_package = "github.com/sonr-io/sonr/x/dwn/types";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
// EventRecordWritten is emitted when a record is written to DWN
message EventRecordWritten {
// Record ID
string record_id = 1;
// Target DID
string target = 2;
// Protocol URI
string protocol = 3;
// Schema URI
string schema = 4;
// Data CID
string data_cid = 5;
// Data size in bytes
uint64 data_size = 6;
// Whether data is encrypted
bool encrypted = 7;
// Block height
uint64 block_height = 8;
}
// EventRecordDeleted is emitted when a record is deleted from DWN
message EventRecordDeleted {
// Record ID
string record_id = 1;
// Target DID
string target = 2;
// Deleter address
string deleter = 3;
// Block height
uint64 block_height = 4;
}
// EventProtocolConfigured is emitted when a protocol is configured
message EventProtocolConfigured {
// Target DID
string target = 1;
// Protocol URI
string protocol_uri = 2;
// Whether protocol is published
bool published = 3;
// Block height
uint64 block_height = 4;
}
// EventPermissionGranted is emitted when a permission is granted
message EventPermissionGranted {
// Permission ID
string permission_id = 1;
// Grantor DID
string grantor = 2;
// Grantee DID
string grantee = 3;
// Interface name
string interface_name = 4;
// Method name
string method = 5;
// Expiration timestamp
google.protobuf.Timestamp expires_at = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = true];
// Block height
uint64 block_height = 7;
}
// EventPermissionRevoked is emitted when a permission is revoked
message EventPermissionRevoked {
// Permission ID
string permission_id = 1;
// Revoker DID
string revoker = 2;
// Block height
uint64 block_height = 3;
}
// EventVaultCreated is emitted when a vault is created
message EventVaultCreated {
// Vault ID
string vault_id = 1;
// Owner DID
string owner = 2;
// Vault public key
string public_key = 3;
// Block height
uint64 block_height = 4;
}
// EventVaultKeysRotated is emitted when vault keys are rotated
message EventVaultKeysRotated {
// Vault ID
string vault_id = 1;
// Owner DID
string owner = 2;
// New public key
string new_public_key = 3;
// Rotation height
uint64 rotation_height = 4;
// Block height
uint64 block_height = 5;
}
// EventKeyRotation is emitted when encryption keys are rotated
message EventKeyRotation {
// Previous key version (0 if first rotation)
uint64 old_key_version = 1;
// New key version
uint64 new_key_version = 2;
// Reason for rotation
string reason = 3;
// Block height when rotation occurred
uint64 block_height = 4;
// Whether running in single node mode
bool single_node_mode = 5;
// Number of validators at time of rotation
uint32 validator_count = 6;
}
+53 -24
View File
@@ -1,44 +1,73 @@
syntax = "proto3";
package dwn.v1;
import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "dwn/v1/state.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/snrd/x/dwn/types";
option go_package = "github.com/sonr-io/sonr/x/dwn/types";
// GenesisState defines the module genesis state
message GenesisState {
// Params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
// DWN Records
repeated DWNRecord records = 2 [(gogoproto.nullable) = false];
// DWN Protocols
repeated DWNProtocol protocols = 3 [(gogoproto.nullable) = false];
// DWN Permissions
repeated DWNPermission permissions = 4 [(gogoproto.nullable) = false];
// Vaults
repeated VaultState vaults = 5 [(gogoproto.nullable) = false];
}
// Params defines the set of module parameters.
message Params {
option (amino.name) = "vault/params";
option (amino.name) = "dwn/params";
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
// Attenuation defines the available attenuations
repeated Attenuation attenuations = 1;
repeated string allowed_operators = 2;
// Maximum size for DWN record data in bytes
uint64 max_record_size = 1;
// Maximum number of protocols per DWN
uint32 max_protocols_per_dwn = 2;
// Maximum number of permissions per DWN
uint32 max_permissions_per_dwn = 3;
// Enable vault creation
bool vault_creation_enabled = 4;
// Minimum vault refresh interval in blocks
uint64 min_vault_refresh_interval = 5;
// Encryption configuration
bool encryption_enabled = 6;
// Key rotation interval in days
uint32 key_rotation_days = 7;
// Minimum validators required for key generation (percentage of active set)
uint32 min_validators_for_key_gen = 8;
// Protocols that require encryption
repeated string encrypted_protocols = 9;
// Schemas that require encryption
repeated string encrypted_schemas = 10;
// Enable single-node fallback for development
bool single_node_fallback = 11;
}
// Attenuation defines the attenuation of a resource
message Attenuation {
Resource resource = 1;
repeated Capability capabilities = 2;
}
// Capability reprensents the available capabilities of a decentralized web node
message Capability {
string name = 1;
string parent = 2;
string description = 3;
repeated string resources = 4;
}
// Resource reprensents the available resources of a decentralized web node
message Resource {
string kind = 1;
string template = 2;
message IPFSStatus {
string peer_id = 1;
string peer_name = 2;
string peer_type = 3;
string version = 4;
}
Regular → Executable
+280 -11
View File
@@ -1,27 +1,87 @@
syntax = "proto3";
package dwn.v1;
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "dwn/v1/genesis.proto";
import "dwn/v1/state.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
option go_package = "github.com/sonr-io/snrd/x/dwn/types";
// ╭─────────────────────────────────────────────────────────╮
// │ RPC Query Service │
// ╰─────────────────────────────────────────────────────────╯
option go_package = "github.com/sonr-io/sonr/x/dwn/types";
// Query provides defines the gRPC querier service.
service Query {
// Params queries all parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/vault/v1/params";
option (google.api.http).get = "/dwn/v1/params";
}
// IPFS queries the status of the IPFS node
rpc IPFS(QueryIPFSRequest) returns (QueryIPFSResponse) {
option (google.api.http).get = "/dwn/v1/ipfs";
}
// CID returns the data for a given CID
rpc CID(QueryCIDRequest) returns (QueryCIDResponse) {
option (google.api.http).get = "/dwn/v1/ipfs/{cid}";
}
// Records queries DWN records with filters
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dwn_docs.md"}}
rpc Records(QueryRecordsRequest) returns (QueryRecordsResponse) {
option (google.api.http).get = "/dwn/v1/records/{target}";
}
// Record queries a specific DWN record by ID
rpc Record(QueryRecordRequest) returns (QueryRecordResponse) {
option (google.api.http).get = "/dwn/v1/records/{target}/{record_id}";
}
// Protocols queries DWN protocols
rpc Protocols(QueryProtocolsRequest) returns (QueryProtocolsResponse) {
option (google.api.http).get = "/dwn/v1/protocols/{target}";
}
// Protocol queries a specific DWN protocol
rpc Protocol(QueryProtocolRequest) returns (QueryProtocolResponse) {
option (google.api.http).get = "/dwn/v1/protocols/{target}/{protocol_uri}";
}
// Permissions queries DWN permissions
rpc Permissions(QueryPermissionsRequest) returns (QueryPermissionsResponse) {
option (google.api.http).get = "/dwn/v1/permissions/{target}";
}
// Vault queries a specific vault
rpc Vault(QueryVaultRequest) returns (QueryVaultResponse) {
option (google.api.http).get = "/dwn/v1/vaults/{vault_id}";
}
// Vaults queries vaults by owner
rpc Vaults(QueryVaultsRequest) returns (QueryVaultsResponse) {
option (google.api.http).get = "/dwn/v1/vaults";
}
// EncryptedRecord queries a specific encrypted record with automatic decryption
rpc EncryptedRecord(QueryEncryptedRecordRequest) returns (QueryEncryptedRecordResponse) {
option (google.api.http).get = "/dwn/v1/encrypted-records/{target}/{record_id}";
}
// EncryptionStatus queries current encryption key state and version
rpc EncryptionStatus(QueryEncryptionStatusRequest) returns (QueryEncryptionStatusResponse) {
option (google.api.http).get = "/dwn/v1/encryption/status";
}
// VRFContributions lists VRF contributions for current consensus round
rpc VRFContributions(QueryVRFContributionsRequest) returns (QueryVRFContributionsResponse) {
option (google.api.http).get = "/dwn/v1/encryption/vrf-contributions";
}
}
// ╭──────────────────────────────────────────────────────────╮
// │ RPC Query Messages │
// ╰──────────────────────────────────────────────────────────╯
// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}
@@ -30,3 +90,212 @@ message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1;
}
// QueryIPFSRequest is the request type for the Query/IPFS RPC method.
message QueryIPFSRequest {}
// QueryIPFSResponse is the response type for the Query/IPFS RPC method.
message QueryIPFSResponse {
// IPFS status
IPFSStatus status = 1;
}
// QueryCIDRequest is the request type for the Query/CID RPC method.
message QueryCIDRequest {
// CID to query
string cid = 1;
}
// QueryCIDResponse is the response type for the Query/CID RPC method.
message QueryCIDResponse {
// Status code
int32 status_code = 1;
// CID data
bytes data = 2;
}
// QueryRecordsRequest is the request type for querying DWN records
message QueryRecordsRequest {
// Target DWN (DID)
string target = 1;
// Optional protocol filter
string protocol = 2;
// Optional schema filter
string schema = 3;
// Optional parent ID filter
string parent_id = 4;
// Filter by published status
bool published_only = 5;
// Pagination
cosmos.base.query.v1beta1.PageRequest pagination = 6;
}
// QueryRecordsResponse is the response type for querying DWN records
message QueryRecordsResponse {
// List of records
repeated DWNRecord records = 1 [(gogoproto.nullable) = false];
// Pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryRecordRequest is the request type for querying a specific DWN record
message QueryRecordRequest {
// Target DWN (DID)
string target = 1;
// Record ID
string record_id = 2;
}
// QueryRecordResponse is the response type for querying a specific DWN record
message QueryRecordResponse {
// The record
DWNRecord record = 1;
}
// QueryProtocolsRequest is the request type for querying DWN protocols
message QueryProtocolsRequest {
// Target DWN (DID)
string target = 1;
// Filter by published status
bool published_only = 2;
// Pagination
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}
// QueryProtocolsResponse is the response type for querying DWN protocols
message QueryProtocolsResponse {
// List of protocols
repeated DWNProtocol protocols = 1 [(gogoproto.nullable) = false];
// Pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryProtocolRequest is the request type for querying a specific DWN protocol
message QueryProtocolRequest {
// Target DWN (DID)
string target = 1;
// Protocol URI
string protocol_uri = 2;
}
// QueryProtocolResponse is the response type for querying a specific DWN protocol
message QueryProtocolResponse {
// The protocol
DWNProtocol protocol = 1;
}
// QueryPermissionsRequest is the request type for querying DWN permissions
message QueryPermissionsRequest {
// Target DWN (DID)
string target = 1;
// Optional grantor filter
string grantor = 2;
// Optional grantee filter
string grantee = 3;
// Optional interface filter
string interface_name = 4;
// Optional method filter
string method = 5;
// Include revoked permissions
bool include_revoked = 6;
// Pagination
cosmos.base.query.v1beta1.PageRequest pagination = 7;
}
// QueryPermissionsResponse is the response type for querying DWN permissions
message QueryPermissionsResponse {
// List of permissions
repeated DWNPermission permissions = 1 [(gogoproto.nullable) = false];
// Pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryVaultRequest is the request type for querying a specific vault
message QueryVaultRequest {
// Vault ID
string vault_id = 1;
}
// QueryVaultResponse is the response type for querying a specific vault
message QueryVaultResponse {
// The vault
VaultState vault = 1;
}
// QueryVaultsRequest is the request type for querying vaults by owner
message QueryVaultsRequest {
// Optional owner filter
string owner = 1;
// Pagination
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
// QueryVaultsResponse is the response type for querying vaults
message QueryVaultsResponse {
// List of vaults
repeated VaultState vaults = 1 [(gogoproto.nullable) = false];
// Pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryEncryptedRecordRequest is the request type for querying encrypted records
message QueryEncryptedRecordRequest {
// Target DWN (DID)
string target = 1;
// Record ID
string record_id = 2;
// Optional: return encrypted data instead of decrypting
bool return_encrypted = 3;
}
// QueryEncryptedRecordResponse is the response type for querying encrypted records
message QueryEncryptedRecordResponse {
// The record with decrypted data (if requested)
DWNRecord record = 1;
// Encryption metadata for the record
EncryptionMetadata encryption_metadata = 2;
// Whether data was decrypted
bool was_decrypted = 3;
}
// QueryEncryptionStatusRequest is the request type for querying encryption status
message QueryEncryptionStatusRequest {}
// QueryEncryptionStatusResponse is the response type for querying encryption status
message QueryEncryptionStatusResponse {
// Current encryption key version
uint64 current_key_version = 1;
// Current validator set participating in consensus
repeated string validator_set = 2;
// Whether running in single-node mode
bool single_node_mode = 3;
// Last key rotation timestamp
int64 last_rotation = 4;
// Next scheduled rotation timestamp
int64 next_rotation = 5;
// Total encrypted records in the system
uint64 total_encrypted_records = 6;
}
// QueryVRFContributionsRequest is the request type for querying VRF contributions
message QueryVRFContributionsRequest {
// Optional: filter by validator address
string validator_address = 1;
// Optional: filter by block height
int64 block_height = 2;
// Pagination
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}
// QueryVRFContributionsResponse is the response type for querying VRF contributions
message QueryVRFContributionsResponse {
// List of VRF contributions
repeated VRFContribution contributions = 1 [(gogoproto.nullable) = false];
// Current consensus round information
VRFConsensusRound current_round = 2;
// Pagination response
cosmos.base.query.v1beta1.PageResponse pagination = 3;
}
+363 -23
View File
@@ -3,31 +3,371 @@ package dwn.v1;
import "cosmos/orm/v1/orm.proto";
option go_package = "github.com/sonr-io/snrd/x/dwn/types";
option go_package = "github.com/sonr-io/sonr/x/dwn/types";
// https://github.com/cosmos/cosmos-sdk/blob/main/orm/README.md
message Credential {
option (cosmos.orm.v1.table) = {
id: 1;
primary_key: { fields: "id" }
};
bytes id = 1; // The credential ID as a byte array
string kind = 2; // The credential type (e.g. "public-key")
repeated string transports = 3; // Optional transport hints (usb, nfc, ble, internal)
bytes public_key = 4; // The credential's public key
string attestation_type = 5; // The attestation type used (e.g. "none", "indirect", etc)
uint64 created_at = 6; // Timestamp of when the credential was created
// EncryptionMetadata contains metadata for consensus-based encryption
message EncryptionMetadata {
// Encryption algorithm used (e.g., "AES-256-GCM")
string algorithm = 1;
// Input used for VRF consensus key derivation
bytes consensus_input = 2;
// Nonce used for encryption
bytes nonce = 3;
// Authentication tag from AES-GCM
bytes auth_tag = 4;
// Block height when encryption was performed
int64 encryption_height = 5;
// Validator set participating in consensus
repeated string validator_set = 6;
// Key rotation version
uint64 key_version = 7;
// Single node development mode flag
bool single_node_mode = 8;
// HMAC-SHA256 authentication tag for data integrity
bytes data_hmac = 9;
// Salt used for key derivation
bytes key_derivation_salt = 10;
// Additional authenticated data (AAD) for AES-GCM
bytes additional_data = 11;
}
message Profile {
option (cosmos.orm.v1.table) = {
id: 2;
primary_key: { fields: "account" }
index: { id: 1 fields: "amount" }
};
// EncryptionKeyState contains the current key and contributions for a given key version
message EncryptionKeyState {
option (cosmos.orm.v1.table) = {
id: 6
primary_key: {fields: "key_version"}
index: {
id: 1
fields: "last_rotation"
unique: false
}
index: {
id: 2
fields: "next_rotation"
unique: false
}
};
bytes account = 1;
uint64 amount = 2;
// Current encryption key (stored encrypted or as reference)
bytes current_key = 1;
// Key version/epoch identifier
uint64 key_version = 2;
// Validator set participating in consensus
repeated string validator_set = 3;
// VRF contributions for this key generation round
repeated VRFContribution contributions = 4;
// Last rotation timestamp (Unix timestamp)
int64 last_rotation = 5;
// Next scheduled rotation timestamp (Unix timestamp)
int64 next_rotation = 6;
// Single node development mode flag
bool single_node_mode = 7;
// Usage count for this key (for usage-based rotation)
uint64 usage_count = 8;
// Maximum usage count before rotation
uint64 max_usage_count = 9;
// Rotation interval in seconds (for time-based rotation)
int64 rotation_interval = 10;
// Key creation timestamp (Unix timestamp)
int64 created_at = 11;
// Previous key version for migration support
uint64 previous_key_version = 12;
}
// VRFConsensusRound tracks a specific consensus round for key generation
message VRFConsensusRound {
option (cosmos.orm.v1.table) = {
id: 7
primary_key: {fields: "round_number"}
index: {
id: 1
fields: "status"
unique: false
}
index: {
id: 2
fields: "expiry_height"
unique: false
}
};
// Round number for this consensus round
uint64 round_number = 1;
// Key version this round is generating
uint64 key_version = 2;
// Number of contributions required for consensus
uint32 required_contributions = 3;
// Number of contributions received so far
uint32 received_contributions = 4;
// Current status: "waiting_for_contributions", "complete", "expired", "single_node_mode"
string status = 5;
// Block height when this round expires
int64 expiry_height = 6;
// Block height when round was initiated
int64 initiated_height = 7;
// Consensus input used for this round
bytes consensus_input = 8;
// Whether this round completed successfully
bool completed = 9;
}
// EncryptionStats contains encryption statistics for monitoring
message EncryptionStats {
// Total number of encrypted records
int64 total_encrypted_records = 1;
// Total number of decryption errors
int64 total_decryption_errors = 2;
// Last encryption height
int64 last_encryption_height = 3;
}
// SaltStore contains salt management for encryption operations
message SaltStore {
option (cosmos.orm.v1.table) = {
id: 8
primary_key: {fields: "record_id"}
index: {
id: 1
fields: "created_at"
unique: false
}
};
// Unique identifier for the encrypted record
string record_id = 1;
// Salt value used for key derivation
bytes salt_value = 2;
// Creation timestamp (Unix timestamp)
int64 created_at = 3;
// Key version associated with this salt
uint64 key_version = 4;
// Algorithm used with this salt (e.g., "PBKDF2-SHA256")
string algorithm = 5;
}
// VRFContribution contains a VRF contribution for a given validator
message VRFContribution {
option (cosmos.orm.v1.table) = {
id: 5
primary_key: {fields: "validator_address,block_height"}
index: {
id: 1
fields: "block_height"
unique: false
}
index: {
id: 2
fields: "timestamp"
unique: false
}
};
// Validator address
string validator_address = 1;
// VRF randomness output
bytes randomness = 2;
// VRF proof for verification
bytes proof = 3;
// Block height when contribution was made
int64 block_height = 4;
// Unix timestamp when contribution was submitted
int64 timestamp = 5;
}
// EncryptedDWNRecord contains an encrypted DWN record
message EncryptedDWNRecord {
// Unique identifier for the record
string record_id = 1;
// Encrypted data
bytes encrypted_data = 2;
// Nonce used for encryption
bytes nonce = 3;
// Key version
uint64 key_version = 4;
// IPFS hash of the record data
string ipfs_hash = 5;
}
// EnclaveData represents encrypted private key material within a secure enclave
message EnclaveData {
// Encrypted private key material from the WASM enclave
bytes private_data = 1;
// Public key corresponding to the private key
bytes public_key = 2;
// Unique identifier for the enclave instance
string enclave_id = 3;
// Version number for refresh tracking
int64 version = 4;
}
// DWNMessageDescriptor contains metadata about a DWN message
message DWNMessageDescriptor {
// Interface type (e.g., "Records", "Protocols", "Permissions")
string interface_name = 1;
// Method name (e.g., "Write", "Query", "Configure")
string method = 2;
// ISO 8601 timestamp of when the message was created
string message_timestamp = 3;
// CID of the message data
string data_cid = 4;
// Size of the data in bytes
int64 data_size = 5;
// MIME type of the data
string data_format = 6;
}
// DWNRecord represents a record stored in a Decentralized Web Node
message DWNRecord {
option (cosmos.orm.v1.table) = {
id: 1
primary_key: {fields: "record_id"}
index: {
id: 1
fields: "target,protocol"
unique: false
}
index: {
id: 2
fields: "target,schema"
unique: false
}
index: {
id: 3
fields: "parent_id"
unique: false
}
};
// Unique identifier for the record
string record_id = 1;
// DID of the DWN target
string target = 2;
// Message descriptor
DWNMessageDescriptor descriptor = 3;
// Authorization JWT or signature
string authorization = 4;
// Record data payload
bytes data = 5;
// Optional protocol URI this record conforms to
string protocol = 6;
// Optional protocol path
string protocol_path = 7;
// Optional schema URI for data validation
string schema = 8;
// Optional parent record ID for threading
string parent_id = 9;
// Published flag for public visibility
bool published = 10;
// Attestation signature
string attestation = 11;
// Encryption details (legacy field)
string encryption = 12;
// Key derivation scheme (legacy field)
string key_derivation_scheme = 13;
// Creation timestamp (Unix timestamp)
int64 created_at = 14;
// Last update timestamp (Unix timestamp)
int64 updated_at = 15;
// Block height when created
int64 created_height = 16;
// Encryption metadata for consensus-based encryption
EncryptionMetadata encryption_metadata = 17;
// Flag indicating if the record is encrypted
bool is_encrypted = 18;
}
// DWNProtocol represents a configured protocol in a DWN
message DWNProtocol {
option (cosmos.orm.v1.table) = {
id: 2
primary_key: {fields: "target,protocol_uri"}
};
// DID of the DWN target
string target = 1;
// Protocol URI identifier
string protocol_uri = 2;
// Protocol definition JSON
bytes definition = 3;
// Published flag for discoverability
bool published = 4;
// Creation timestamp (Unix timestamp)
int64 created_at = 5;
// Block height when created
int64 created_height = 6;
}
// DWNPermission represents a permission grant in a DWN
message DWNPermission {
option (cosmos.orm.v1.table) = {
id: 3
primary_key: {fields: "permission_id"}
index: {
id: 1
fields: "grantor,grantee"
unique: false
}
index: {
id: 2
fields: "target,interface_name,method"
unique: false
}
};
// Unique identifier for the permission
string permission_id = 1;
// DID of the permission grantor
string grantor = 2;
// DID of the permission grantee
string grantee = 3;
// DID of the DWN target
string target = 4;
// Interface scope (e.g., "Records", "Protocols")
string interface_name = 5;
// Method scope (e.g., "Write", "Query")
string method = 6;
// Optional protocol scope
string protocol = 7;
// Optional record scope
string record_id = 8;
// Permission conditions JSON
bytes conditions = 9;
// Expiration timestamp (Unix timestamp)
int64 expires_at = 10;
// Creation timestamp (Unix timestamp)
int64 created_at = 11;
// Revoked flag
bool revoked = 12;
// Block height when created
int64 created_height = 13;
}
// VaultState represents a vault instance for enclave-based operations
message VaultState {
option (cosmos.orm.v1.table) = {
id: 4
primary_key: {fields: "vault_id"}
index: {
id: 1
fields: "owner"
unique: false
}
};
// Unique identifier for the vault
string vault_id = 1;
// Owner DID or address
string owner = 2;
// Enclave data containing encrypted keys
EnclaveData enclave_data = 3;
// Public key for verification
bytes public_key = 4;
// Creation timestamp (Unix timestamp)
int64 created_at = 5;
// Last refresh timestamp (Unix timestamp)
int64 last_refreshed = 6;
// Block height when created
int64 created_height = 7;
// Encryption metadata for consensus-based encryption
EncryptionMetadata encryption_metadata = 8;
}
+188 -31
View File
@@ -2,28 +2,41 @@ syntax = "proto3";
package dwn.v1;
import "cosmos/msg/v1/msg.proto";
import "dwn/v1/genesis.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "dwn/v1/genesis.proto";
import "dwn/v1/state.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/sonr-io/snrd/x/dwn/types";
option go_package = "github.com/sonr-io/sonr/x/dwn/types";
// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
// UpdateParams defines a governance operation for updating the parameters.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// DWN Records Operations
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "dwn_docs.md"}}
rpc RecordsWrite(MsgRecordsWrite) returns (MsgRecordsWriteResponse);
rpc RecordsDelete(MsgRecordsDelete) returns (MsgRecordsDeleteResponse);
// Spawn spawns a new Vault
rpc Initialize(MsgInitialize) returns (MsgInitializeResponse);
// DWN Protocols Operations
rpc ProtocolsConfigure(MsgProtocolsConfigure) returns (MsgProtocolsConfigureResponse);
// DWN Permissions Operations
rpc PermissionsGrant(MsgPermissionsGrant) returns (MsgPermissionsGrantResponse);
rpc PermissionsRevoke(MsgPermissionsRevoke) returns (MsgPermissionsRevokeResponse);
// DWN Vault Operations
rpc RotateVaultKeys(MsgRotateVaultKeys) returns (MsgRotateVaultKeysResponse);
}
// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
@@ -31,35 +44,179 @@ message MsgUpdateParams {
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// params defines the parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}
// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
// MsgSpawn spawns a New Vault with Unclaimed State. This is a one-time
// operation that must be performed interacting with the Vault.
//
// Since: cosmos-sdk 0.47
message MsgInitialize {
option (cosmos.msg.v1.signer) = "authority";
// MsgRecordsWrite creates or updates a record in the DWN
message MsgRecordsWrite {
option (cosmos.msg.v1.signer) = "author";
// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// params defines the parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
// Author of the record (DID or cosmos address)
string author = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Target DWN (DID)
string target = 2;
// Message descriptor
DWNMessageDescriptor descriptor = 3;
// Authorization JWT/signature
string authorization = 4;
// Record data
bytes data = 5;
// Optional protocol URI
string protocol = 6;
// Optional protocol path
string protocol_path = 7;
// Optional schema URI
string schema = 8;
// Optional parent record ID
string parent_id = 9;
// Published flag
bool published = 10;
// Optional encryption details
string encryption = 11;
// Optional attestation
string attestation = 12;
}
// MsgSpawnResponse defines the response structure for executing a
// MsgSpawn message.
//
// Since: cosmos-sdk 0.47
message MsgInitializeResponse {}
// MsgRecordsWriteResponse defines the response for RecordsWrite
message MsgRecordsWriteResponse {
// Record ID of the created/updated record
string record_id = 1;
// CID of the data
string data_cid = 2;
}
// MsgRecordsDelete deletes a record from the DWN
message MsgRecordsDelete {
option (cosmos.msg.v1.signer) = "author";
// Author requesting deletion (DID or cosmos address)
string author = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Target DWN (DID)
string target = 2;
// Record ID to delete
string record_id = 3;
// Message descriptor
DWNMessageDescriptor descriptor = 4;
// Authorization JWT/signature
string authorization = 5;
// Prune descendants flag
bool prune = 6;
}
// MsgRecordsDeleteResponse defines the response for RecordsDelete
message MsgRecordsDeleteResponse {
// Success flag
bool success = 1;
// Number of records deleted (including pruned)
int32 deleted_count = 2;
}
// MsgProtocolsConfigure configures a protocol in the DWN
message MsgProtocolsConfigure {
option (cosmos.msg.v1.signer) = "author";
// Author configuring the protocol (DID or cosmos address)
string author = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Target DWN (DID)
string target = 2;
// Message descriptor
DWNMessageDescriptor descriptor = 3;
// Authorization JWT/signature
string authorization = 4;
// Protocol URI
string protocol_uri = 5;
// Protocol definition JSON
bytes definition = 6;
// Published flag
bool published = 7;
}
// MsgProtocolsConfigureResponse defines the response for ProtocolsConfigure
message MsgProtocolsConfigureResponse {
// Protocol URI that was configured
string protocol_uri = 1;
// Success flag
bool success = 2;
}
// MsgPermissionsGrant grants permissions in the DWN
message MsgPermissionsGrant {
option (cosmos.msg.v1.signer) = "grantor";
// Grantor of the permission (DID or cosmos address)
string grantor = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Grantee receiving the permission (DID)
string grantee = 2;
// Target DWN (DID)
string target = 3;
// Message descriptor
DWNMessageDescriptor descriptor = 4;
// Authorization JWT/signature
string authorization = 5;
// Interface scope
string interface_name = 6;
// Method scope
string method = 7;
// Optional protocol scope
string protocol = 8;
// Optional record scope
string record_id = 9;
// Permission conditions JSON
bytes conditions = 10;
// Expiration timestamp (Unix timestamp)
int64 expires_at = 11;
}
// MsgPermissionsGrantResponse defines the response for PermissionsGrant
message MsgPermissionsGrantResponse {
// Permission ID of the created grant
string permission_id = 1;
}
// MsgPermissionsRevoke revokes permissions in the DWN
message MsgPermissionsRevoke {
option (cosmos.msg.v1.signer) = "grantor";
// Grantor revoking the permission (DID or cosmos address)
string grantor = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Permission ID to revoke
string permission_id = 2;
// Message descriptor
DWNMessageDescriptor descriptor = 3;
// Authorization JWT/signature
string authorization = 4;
}
// MsgPermissionsRevokeResponse defines the response for PermissionsRevoke
message MsgPermissionsRevokeResponse {
// Success flag
bool success = 1;
}
// MsgRotateVaultKeys rotates encryption keys for existing vaults
message MsgRotateVaultKeys {
option (cosmos.msg.v1.signer) = "authority";
// Authority performing the rotation (governance or validator)
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Vault ID to rotate keys for (empty means all vaults)
string vault_id = 2;
// Reason for rotation
string reason = 3;
// Force rotation even if not due
bool force = 4;
}
// MsgRotateVaultKeysResponse defines the response for RotateVaultKeys
message MsgRotateVaultKeysResponse {
// Number of vaults affected
uint32 vaults_rotated = 1;
// New key version after rotation
uint64 new_key_version = 2;
// Success flag
bool success = 3;
}
Regular → Executable
+1 -3
View File
@@ -7,7 +7,5 @@ import "cosmos/app/v1alpha1/module.proto";
// Module is the app config object of the module.
// Learn more: https://docs.cosmos.network/main/building-modules/depinject
message Module {
option (cosmos.app.v1alpha1.module) = {
go_import : "github.com/sonr-io/snrd"
};
option (cosmos.app.v1alpha1.module) = {go_import: "github.com/sonr-io/sonr"};
}
+65
View File
@@ -0,0 +1,65 @@
syntax = "proto3";
package svc.v1;
option go_package = "github.com/sonr-io/sonr/x/svc/types";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
// EventDomainVerificationInitiated is emitted when domain verification is initiated
message EventDomainVerificationInitiated {
// Domain being verified
string domain = 1;
// Verification ID
string verification_id = 2;
// Verification challenge
string challenge = 3;
// Initiator address
string initiator = 4;
// Block height
uint64 block_height = 5;
}
// EventDomainVerified is emitted when a domain is successfully verified
message EventDomainVerified {
// Domain that was verified
string domain = 1;
// Verification ID
string verification_id = 2;
// Verifier address
string verifier = 3;
// Verification timestamp
google.protobuf.Timestamp verified_at = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
// Block height
uint64 block_height = 5;
}
// EventServiceRegistered is emitted when a service is registered
message EventServiceRegistered {
// Service ID
string service_id = 1;
// Associated domain
string domain = 2;
// Owner DID
string owner = 3;
// Service endpoints
repeated string endpoints = 4;
// Service metadata (JSON string)
string metadata = 5;
// Block height
uint64 block_height = 6;
}
+61 -34
View File
@@ -1,54 +1,81 @@
syntax = "proto3";
package svc.v1;
import "gogoproto/gogo.proto";
import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "svc/v1/state.proto";
option go_package = "github.com/sonr-io/snrd/x/svc/types";
option go_package = "github.com/sonr-io/sonr/x/svc/types";
// GenesisState defines the module genesis state
message GenesisState {
// Params defines all the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
Params params = 1 [(gogoproto.nullable) = false];
// Service capabilities stored in the module
repeated ServiceCapability capabilities = 2 [(gogoproto.nullable) = false];
}
// Params defines the set of module parameters.
message Params {
option (amino.name) = "service/params";
option (amino.name) = "svc/params";
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
repeated Attenuation attenuations = 1;
}
// Service Limits
// Maximum number of services that can be registered per account
uint32 max_services_per_account = 1;
// Maximum number of domains that can be bound to a single service
uint32 max_domains_per_service = 2;
// Maximum number of endpoints that can be registered per service
uint32 max_endpoints_per_service = 3;
// Attenuation defines the attenuation of a resource
message Attenuation {
Resource resource = 1;
repeated Capability capabilities = 2;
}
// Timeouts and Intervals (in seconds)
// Time allowed for domain ownership verification before expiry
int64 domain_verification_timeout = 4;
// Interval between service health checks
int64 service_health_check_interval = 5;
// Default expiration time for capabilities if not specified
int64 capability_default_expiration = 6;
// Capability reprensents the available capabilities of a decentralized web node
message Capability {
string name = 1;
string parent = 2;
string description = 3;
repeated string resources = 4;
}
// Economic Parameters
// Fee required to register a new service
cosmos.base.v1beta1.Coin service_registration_fee = 7
[(gogoproto.nullable) = false];
// Fee required to verify domain ownership
cosmos.base.v1beta1.Coin domain_verification_fee = 8
[(gogoproto.nullable) = false];
// Minimum stake required to keep a service active
cosmos.base.v1beta1.Coin min_service_stake = 9
[(gogoproto.nullable) = false];
// Resource reprensents the available resources of a decentralized web node
message Resource {
string kind = 1;
string template = 2;
}
// UCAN and Capability Settings
// Maximum depth of delegation chains for capabilities
uint32 max_delegation_chain_depth = 10;
// Maximum lifetime for UCAN tokens (in seconds)
int64 ucan_max_lifetime = 11;
// Minimum lifetime for UCAN tokens (in seconds)
int64 ucan_min_lifetime = 12;
// List of supported signature algorithms for UCAN
repeated string supported_signature_algorithms = 13;
// Service defines a Decentralized Service on the Sonr Blockchain
message Service {
string id = 1;
string authority = 2;
repeated string origins = 3;
string name = 4;
string description = 5;
repeated Attenuation attenuations = 6;
repeated string tags = 7;
int64 expiry_height = 8;
}
// Validation Rules
// Whether to require cryptographic proof of domain ownership
bool require_domain_ownership_proof = 14;
// Whether to require HTTPS for service endpoints
bool require_https = 15;
// Whether to allow localhost domains for development
bool allow_localhost = 16;
// Maximum length for service description text
uint32 max_service_description_length = 17;
// Rate Limiting
// Maximum number of service registrations allowed per block
uint32 max_registrations_per_block = 18;
// Maximum number of service updates allowed per block
uint32 max_updates_per_block = 19;
// Maximum number of capability grants allowed per block
uint32 max_capability_grants_per_block = 20;
}
+189 -23
View File
@@ -3,8 +3,9 @@ package svc.v1;
import "google/api/annotations.proto";
import "svc/v1/genesis.proto";
import "svc/v1/state.proto";
option go_package = "github.com/sonr-io/snrd/x/svc/types";
option go_package = "github.com/sonr-io/sonr/x/svc/types";
// Query provides defines the gRPC querier service.
service Query {
@@ -13,14 +14,44 @@ service Query {
option (google.api.http).get = "/svc/v1/params";
}
// OriginExists queries if a given origin exists.
rpc OriginExists(QueryOriginExistsRequest) returns (QueryOriginExistsResponse) {
option (google.api.http).get = "/svc/v1/origins/{origin}";
// DomainVerification queries domain verification status by domain name.
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "svc_docs.md"}}
rpc DomainVerification(QueryDomainVerificationRequest) returns (QueryDomainVerificationResponse) {
option (google.api.http).get = "/svc/v1/domain/{domain}";
}
// ResolveOrigin queries the domain of a given service and returns its record with capabilities.
rpc ResolveOrigin(QueryResolveOriginRequest) returns (QueryResolveOriginResponse) {
option (google.api.http).get = "/svc/v1/origins/{origin}/record";
// Service queries service information by service ID.
rpc Service(QueryServiceRequest) returns (QueryServiceResponse) {
option (google.api.http).get = "/svc/v1/service/{service_id}";
}
// ServicesByOwner queries all services owned by a specific address.
rpc ServicesByOwner(QueryServicesByOwnerRequest) returns (QueryServicesByOwnerResponse) {
option (google.api.http).get = "/svc/v1/services/owner/{owner}";
}
// ServicesByDomain queries services bound to a specific domain.
rpc ServicesByDomain(QueryServicesByDomainRequest) returns (QueryServicesByDomainResponse) {
option (google.api.http).get = "/svc/v1/services/domain/{domain}";
}
// ServiceOIDCDiscovery queries OIDC discovery configuration for a service
rpc ServiceOIDCDiscovery(QueryServiceOIDCDiscoveryRequest) returns (QueryServiceOIDCDiscoveryResponse) {
option (google.api.http).get = "/svc/v1/service/{service_id}/oidc/discovery";
}
// ServiceOIDCJWKS queries OIDC JWKS for a service
rpc ServiceOIDCJWKS(QueryServiceOIDCJWKSRequest) returns (QueryServiceOIDCJWKSResponse) {
option (google.api.http).get = "/svc/v1/service/{service_id}/oidc/jwks";
}
// ServiceOIDCMetadata queries OIDC metadata for a service
rpc ServiceOIDCMetadata(QueryServiceOIDCMetadataRequest) returns (QueryServiceOIDCMetadataResponse) {
option (google.api.http).get = "/svc/v1/service/{service_id}/oidc/metadata";
}
}
@@ -33,26 +64,161 @@ message QueryParamsResponse {
Params params = 1;
}
// QueryOriginExistsRequest is the request type for the Query/OriginExists RPC method.
message QueryOriginExistsRequest {
// origin is the origin to query.
string origin = 1;
// QueryDomainVerificationRequest is the request type for the
// Query/DomainVerification RPC method.
message QueryDomainVerificationRequest {
string domain = 1;
}
// QueryOriginExistsResponse is the response type for the Query/OriginExists RPC method.
message QueryOriginExistsResponse {
// exists is the boolean value representing whether the origin exists.
bool exists = 1;
// QueryDomainVerificationResponse is the response type for the
// Query/DomainVerification RPC method.
message QueryDomainVerificationResponse {
DomainVerification domain_verification = 1;
}
// QueryResolveOriginRequest is the request type for the Query/ResolveOrigin RPC method.
message QueryResolveOriginRequest {
// origin is the origin to query.
string origin = 1;
// QueryServiceRequest is the request type for the Query/Service RPC method.
message QueryServiceRequest {
string service_id = 1;
}
// QueryResolveOriginResponse is the response type for the Query/ResolveOrigin RPC method.
message QueryResolveOriginResponse {
// record is the record of the origin.
Service record = 1;
// QueryServiceResponse is the response type for the Query/Service RPC method.
message QueryServiceResponse {
Service service = 1;
}
// QueryServicesByOwnerRequest is the request type for the Query/ServicesByOwner
// RPC method.
message QueryServicesByOwnerRequest {
string owner = 1;
}
// QueryServicesByOwnerResponse is the response type for the
// Query/ServicesByOwner RPC method.
message QueryServicesByOwnerResponse {
repeated Service services = 1;
}
// QueryServicesByDomainRequest is the request type for the
// Query/ServicesByDomain RPC method.
message QueryServicesByDomainRequest {
string domain = 1;
}
// QueryServicesByDomainResponse is the response type for the
// Query/ServicesByDomain RPC method.
message QueryServicesByDomainResponse {
repeated Service services = 1;
}
// QueryServiceOIDCDiscoveryRequest is the request type for the
// Query/ServiceOIDCDiscovery RPC method.
message QueryServiceOIDCDiscoveryRequest {
string service_id = 1;
}
// QueryServiceOIDCDiscoveryResponse is the response type for the
// Query/ServiceOIDCDiscovery RPC method.
// This response follows the OpenID Connect Discovery 1.0 specification
message QueryServiceOIDCDiscoveryResponse {
// The issuer identifier
string issuer = 1;
// URL of the authorization endpoint
string authorization_endpoint = 2;
// URL of the token endpoint
string token_endpoint = 3;
// URL of the JSON Web Key Set
string jwks_uri = 4;
// URL of the UserInfo endpoint
string userinfo_endpoint = 5;
// URL for the registration endpoint
string registration_endpoint = 6;
// JSON array containing a list of the OAuth 2.0 scope values
repeated string scopes_supported = 7;
// JSON array containing a list of the OAuth 2.0 response_type values
repeated string response_types_supported = 8;
// JSON array containing a list of the OAuth 2.0 grant_type values
repeated string grant_types_supported = 9;
// JSON array containing a list of the JWS signing algorithms
repeated string id_token_signing_alg_values_supported = 10;
// JSON array containing a list of the Subject Identifier types
repeated string subject_types_supported = 11;
// JSON array containing a list of client authentication methods
repeated string token_endpoint_auth_methods_supported = 12;
// JSON array containing a list of the Claim Names
repeated string claims_supported = 13;
// JSON array containing a list of the OAuth 2.0 response_mode values
repeated string response_modes_supported = 14;
// Service URL for documentation
string service_documentation = 15;
// Languages supported for the UI
repeated string ui_locales_supported = 16;
// Languages supported for claims
repeated string claims_locales_supported = 17;
// Boolean value specifying whether the OP supports use of the request parameter
bool request_parameter_supported = 18;
// Boolean value specifying whether the OP supports use of the request_uri parameter
bool request_uri_parameter_supported = 19;
// Boolean value specifying whether the OP requires any request_uri values
bool require_request_uri_registration = 20;
// URL that the OP provides to the person registering the Client
string op_policy_uri = 21;
// URL that the OP provides to the person registering the Client
string op_tos_uri = 22;
}
// QueryServiceOIDCJWKSRequest is the request type for the
// Query/ServiceOIDCJWKS RPC method.
message QueryServiceOIDCJWKSRequest {
string service_id = 1;
}
// QueryServiceOIDCJWKSResponse is the response type for the
// Query/ServiceOIDCJWKS RPC method.
// This response follows the JSON Web Key Set specification
message QueryServiceOIDCJWKSResponse {
// Array of JWK values
repeated JWK keys = 1;
}
// QueryServiceOIDCMetadataRequest is the request type for the
// Query/ServiceOIDCMetadata RPC method.
message QueryServiceOIDCMetadataRequest {
string service_id = 1;
}
// QueryServiceOIDCMetadataResponse is the response type for the
// Query/ServiceOIDCMetadata RPC method.
message QueryServiceOIDCMetadataResponse {
// Service-specific OIDC metadata
ServiceOIDCConfig config = 1;
// The verified domain of the service
string verified_domain = 2;
// Service status
ServiceStatus service_status = 3;
// Additional metadata as key-value pairs
map<string, string> metadata = 4;
}
+283 -39
View File
@@ -3,55 +3,299 @@ package svc.v1;
import "cosmos/orm/v1/orm.proto";
option go_package = "github.com/sonr-io/snrd/x/svc/types";
option go_package = "github.com/sonr-io/sonr/x/svc/types";
// https://github.com/cosmos/cosmos-sdk/blob/main/orm/README.md
message Domain {
// Service represents a registered service with domain binding and UCAN
// capabilities
message Service {
option (cosmos.orm.v1.table) = {
id: 1
primary_key: {
fields: "id"
auto_increment: true
}
index: {
id: 1
fields: "origin"
unique: true
}
};
uint64 id = 1;
string origin = 2;
string name = 3;
string description = 4;
string category = 5;
string icon = 6;
repeated string tags = 7;
}
// Metadata represents a DID alias
message Metadata {
option (cosmos.orm.v1.table) = {
id: 2
primary_key: {fields: "id"}
index: {
id: 1
fields: "subject,origin"
fields: "domain"
unique: true
}
index: {
id: 2
fields: "owner"
}
index: {
id: 3
fields: "status"
}
};
// Unique identifier for the service
string id = 1;
// DNS-verified domain bound to this service
string domain = 2;
// Owner address who registered the service
string owner = 3;
// IPFS CID of the UCAN root capability for this service
string root_capability_cid = 4;
// List of permissions granted to this service
repeated string permissions = 5;
// Current status of the service
ServiceStatus status = 6;
// Unix timestamp when the service was registered
int64 created_at = 7;
// Unix timestamp of last update
int64 updated_at = 8;
}
// DomainVerification represents a domain ownership verification record
message DomainVerification {
option (cosmos.orm.v1.table) = {
id: 2
primary_key: {fields: "domain"}
index: {
id: 1
fields: "owner"
}
index: {
id: 2
fields: "status"
}
};
// The domain being verified (e.g., "example.com")
string domain = 1;
// The owner's address who initiated the verification
string owner = 2;
// Unique verification token to be placed in DNS TXT record
string verification_token = 3;
// Current status of domain verification
DomainVerificationStatus status = 4;
// Unix timestamp when the verification expires if not completed
int64 expires_at = 5;
// Unix timestamp when the domain was verified (if applicable)
int64 verified_at = 6;
}
// DomainVerificationStatus represents the current state of domain verification
enum DomainVerificationStatus {
// Pending verification - DNS TXT record not yet confirmed
DOMAIN_VERIFICATION_STATUS_PENDING = 0;
// Successfully verified - DNS TXT record confirmed
DOMAIN_VERIFICATION_STATUS_VERIFIED = 1;
// Verification expired - exceeded time limit
DOMAIN_VERIFICATION_STATUS_EXPIRED = 2;
// Verification failed - DNS lookup failed or record mismatch
DOMAIN_VERIFICATION_STATUS_FAILED = 3;
}
// ServiceCapability represents a service-specific capability with permissions
message ServiceCapability {
option (cosmos.orm.v1.table) = {
id: 3
primary_key: {fields: "capability_id"}
index: {
id: 1
fields: "service_id"
}
index: {
id: 2
fields: "owner"
}
index: {
id: 3
fields: "revoked"
}
};
// Unique identifier for the capability
string capability_id = 1;
// Service ID this capability belongs to
string service_id = 2;
// DNS domain associated with the capability
string domain = 3;
// List of abilities/actions granted by this capability
repeated string abilities = 4;
// Owner address who holds this capability
string owner = 5;
// Unix timestamp when the capability was created
int64 created_at = 6;
// Unix timestamp when the capability expires (0 for no expiration)
int64 expires_at = 7;
// Whether this capability has been revoked
bool revoked = 8;
}
// ServiceResource represents a resource that can be accessed with capabilities
message ServiceResource {
option (cosmos.orm.v1.table) = {
id: 4
primary_key: {fields: "resource_id"}
index: {
id: 1
fields: "service_id"
}
index: {
id: 2
fields: "resource_type"
}
};
// Unique identifier for the resource
string resource_id = 1;
// Service ID this resource belongs to
string service_id = 2;
// Type of resource (e.g., "api", "data", "file")
string resource_type = 3;
// List of abilities that can be performed on this resource
repeated string allowed_abilities = 4;
// Additional metadata for the resource
map<string, string> metadata = 5;
}
// ServiceStatus represents the operational state of a service
enum ServiceStatus {
// Service is active and operational
SERVICE_STATUS_ACTIVE = 0;
// Service is temporarily suspended
SERVICE_STATUS_SUSPENDED = 1;
// Service has been permanently revoked
SERVICE_STATUS_REVOKED = 2;
}
// ServiceOIDCConfig represents OpenID Connect configuration for a service
message ServiceOIDCConfig {
option (cosmos.orm.v1.table) = {
id: 5
primary_key: {fields: "service_id"}
index: {
id: 1
fields: "issuer"
unique: true
}
};
// The unique identifier of the alias
string id = 1;
// The alias of the DID
string subject = 2;
// Origin of the alias
string origin = 3;
// Controller of the alias
string controller = 4;
// Service ID this OIDC config belongs to
string service_id = 1;
// OIDC issuer URL (must match the service's verified domain)
string issuer = 2;
// Authorization endpoint URL
string authorization_endpoint = 3;
// Token endpoint URL
string token_endpoint = 4;
// JWKS URI for public key retrieval
string jwks_uri = 5;
// UserInfo endpoint URL
string userinfo_endpoint = 6;
// Supported OIDC scopes for this service
repeated string scopes_supported = 7;
// Supported response types
repeated string response_types_supported = 8;
// Supported grant types
repeated string grant_types_supported = 9;
// ID token signing algorithm values supported
repeated string id_token_signing_alg_values_supported = 10;
// Subject types supported
repeated string subject_types_supported = 11;
// Token endpoint auth methods supported
repeated string token_endpoint_auth_methods_supported = 12;
// Claims supported in ID tokens
repeated string claims_supported = 13;
// Response modes supported
repeated string response_modes_supported = 14;
// Additional OIDC metadata as key-value pairs
map<string, string> metadata = 15;
// Unix timestamp when this config was created
int64 created_at = 16;
// Unix timestamp when this config was last updated
int64 updated_at = 17;
}
// JWK represents a JSON Web Key for OIDC
message JWK {
// Key type (e.g., "RSA", "EC")
string kty = 1;
// Key use (e.g., "sig", "enc")
string use = 2;
// Key ID
string kid = 3;
// Algorithm (e.g., "RS256", "ES256")
string alg = 4;
// RSA modulus (for RSA keys)
string n = 5;
// RSA exponent (for RSA keys)
string e = 6;
// Elliptic curve (for EC keys)
string crv = 7;
// X coordinate (for EC keys)
string x = 8;
// Y coordinate (for EC keys)
string y = 9;
}
// ServiceJWKS represents the JSON Web Key Set for a service
message ServiceJWKS {
option (cosmos.orm.v1.table) = {
id: 6
primary_key: {fields: "service_id"}
};
// Service ID this JWKS belongs to
string service_id = 1;
// List of public keys
repeated JWK keys = 2;
// Unix timestamp when this JWKS was last rotated
int64 rotated_at = 3;
}
+93
View File
@@ -0,0 +1,93 @@
## Overview
The SVC (Service) module manages service registration with domain verification and UCAN-based authorization.
## Request: {{.RequestType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .RequestType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Response: {{.ResponseType.Name}}
| Field ID | Name | Type | Description |
| -------- | ---- | ---- | ----------- | {{range .ResponseType.Fields}}
| {{.Number}} | {{.Name}} | {{if eq .Label.String "LABEL_REPEATED"}}[]{{end}}{{.Type}} | {{fieldcomments .Message .}} | {{end}}
## Implementation Details
{{if eq .MethodDescriptorProto.Name "InitiateDomainVerification"}}
- Starts domain ownership verification process
- Generates unique verification token
- Requires DNS TXT record setup
- Provides clear instructions for domain setup
{{else if eq .MethodDescriptorProto.Name "VerifyDomain"}}
- Validates DNS TXT records for domain ownership
- Checks for correct verification token
- Establishes trust for service binding
- One-time verification persists on-chain
{{else if eq .MethodDescriptorProto.Name "RegisterService"}}
- Registers services with verified domains
- Binds service to specific domain endpoints
- Establishes permission boundaries
- Creates root capability with UCAN
{{else if eq .MethodDescriptorProto.Name "Params"}}
- Returns module configuration parameters
- Shows verification timeout settings
- Lists supported service types
{{else if eq .MethodDescriptorProto.Name "DomainVerification"}}
- Queries domain verification status
- Returns verification token if pending
- Shows verification timestamp if completed
{{else if eq .MethodDescriptorProto.Name "Service"}}
- Retrieves service details by ID
- Returns bound domain and permissions
- Shows UCAN capability chain
{{else if eq .MethodDescriptorProto.Name "ServicesByOwner"}}
- Lists all services owned by an address
- Useful for service management interfaces
- Returns service metadata and status
{{else if eq .MethodDescriptorProto.Name "ServicesByDomain"}}
- Finds services bound to a domain
- Supports service discovery by domain
- Returns active service endpoints
{{end}}
## Domain Verification Process
1. **Initiate**: Generate verification token
2. **Configure**: Add DNS TXT record with token
3. **Verify**: Check DNS records for ownership proof
4. **Register**: Bind services to verified domain
## UCAN Authorization
- **Delegation Chain**: Hierarchical permission delegation
- **Capability-based**: Fine-grained access control
- **JWT Format**: Standard token representation
- **Root Capabilities**: Stored on IPFS with CID reference
## Security Features
- Domain ownership verification prevents impersonation
- UCAN tokens enable secure delegation
- Permission scoping limits service capabilities
- On-chain verification audit trail
## Usage Examples
```bash
# Initiate domain verification
snrd tx svc initiate-domain-verification example.com
# Verify domain ownership
snrd tx svc verify-domain example.com
# Register service
snrd tx svc register-service service-1 example.com --permissions read,write
# Query verification status
snrd query svc domain example.com
# List services for domain
snrd query svc services-by-domain example.com
```
+77 -15
View File
@@ -2,11 +2,11 @@ syntax = "proto3";
package svc.v1;
import "cosmos/msg/v1/msg.proto";
import "svc/v1/genesis.proto";
import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "svc/v1/genesis.proto";
option go_package = "github.com/sonr-io/snrd/x/svc/types";
option go_package = "github.com/sonr-io/sonr/x/svc/types";
// Msg defines the Msg service.
service Msg {
@@ -17,8 +17,18 @@ service Msg {
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// RegisterService initializes a Service with a given permission scope and
// URI. The domain must have a valid TXT record containing the public key.
// InitiateDomainVerification starts the domain verification process
//
// {{.MethodDescriptorProto.Name}} is a call with the method(s) {{$first := true}}{{range .Bindings}}{{if $first}}{{$first = false}}{{else}}, {{end}}{{.HTTPMethod}}{{end}} within the "{{.Service.Name}}" service.
// It takes in "{{.RequestType.Name}}" and returns a "{{.ResponseType.Name}}".
//
// {{import "svc_docs.md"}}
rpc InitiateDomainVerification(MsgInitiateDomainVerification) returns (MsgInitiateDomainVerificationResponse);
// VerifyDomain completes domain verification by checking DNS TXT records
rpc VerifyDomain(MsgVerifyDomain) returns (MsgVerifyDomainResponse);
// RegisterService registers a new service with verified domain binding
rpc RegisterService(MsgRegisterService) returns (MsgRegisterServiceResponse);
}
@@ -43,20 +53,72 @@ message MsgUpdateParams {
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
// MsgRegisterService is the message type for the RegisterService RPC.
// MsgInitiateDomainVerification initiates domain ownership verification
message MsgInitiateDomainVerification {
option (cosmos.msg.v1.signer) = "creator";
// Address of the user initiating domain verification
string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Domain to be verified (e.g., "example.com")
string domain = 2;
}
// MsgInitiateDomainVerificationResponse defines the response for domain
// verification initiation
message MsgInitiateDomainVerificationResponse {
// Verification token to be placed in DNS TXT record
string verification_token = 1;
// Instructions for DNS TXT record setup
string dns_instruction = 2;
}
// MsgVerifyDomain verifies domain ownership by checking DNS TXT records
message MsgVerifyDomain {
option (cosmos.msg.v1.signer) = "creator";
// Address of the user verifying domain ownership
string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Domain to be verified
string domain = 2;
}
// MsgVerifyDomainResponse defines the response for domain verification
message MsgVerifyDomainResponse {
// Whether verification was successful
bool verified = 1;
// Message describing verification result
string message = 2;
}
// MsgRegisterService registers a new service with verified domain binding
message MsgRegisterService {
option (cosmos.msg.v1.signer) = "controller";
option (cosmos.msg.v1.signer) = "creator";
// authority is the address of the governance account.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Address of the service owner
string creator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// origin is the origin of the request in wildcard form. Requires valid TXT
// record in DNS.
Service service = 2;
// Unique identifier for the service
string service_id = 2;
// Verified domain to bind to this service
string domain = 3;
// List of permissions requested for this service
repeated string requested_permissions = 4;
// UCAN delegation chain for authorization (JWT-encoded)
string ucan_delegation_chain = 5;
}
// MsgRegisterServiceResponse is the response type for the RegisterService RPC.
// MsgRegisterServiceResponse defines the response for service registration
message MsgRegisterServiceResponse {
bool success = 1;
string did = 2;
// IPFS CID of the generated root capability
string root_capability_cid = 1;
// Service registration details
string service_id = 2;
}