feature/refactor did state (#10)

* feat(did): remove account types

* feat: Refactor Property to Proof in zkprop.go

* feat: add ZKP proof mechanism for verifications

* fix: return bool and error from pinInitialVault

* feat: implement KeyshareSet for managing user and validator keyshares

* feat: Update Credential type in protobuf

* feat: update credential schema with sign count

* feat: migrate  and  modules to middleware

* refactor: rename vault module to ORM

* chore(dwn): add service worker registration to index template

* feat: integrate service worker for offline functionality

* refactor(did): use DIDNamespace enum for verification method in proto reflection

* refactor: update protobuf definitions to support Keyshare

* feat: expose did keeper in app keepers

* Add Motr Web App

* refactor: rename motr/handlers/discovery.go to motr/handlers/openid.go

* refactor: move session related code to middleware

* feat: add database operations for managing assets, chains, and credentials

* feat: add htmx support for UI updates

* refactor: extract common helper scripts

* chore: remove unused storage GUI components

* refactor: Move frontend rendering to dedicated handlers

* refactor: rename  to

* refactor: move alert implementation to templ

* feat: add alert component with icon, title, and message

* feat: add new RequestHeaders struct to store request headers

* Feature/create home view (#9)

* refactor: move view logic to new htmx handler

* refactor: remove unnecessary dependencies

* refactor: remove unused dependencies

* feat(devbox): integrate air for local development

* feat: implement openid connect discovery document

* refactor: rename  to

* refactor(did): update service handling to support DNS discovery

* feat: add support for user and validator keyshares

* refactor: move keyshare signing logic to signer
This commit is contained in:
Prad Nukala
2024-09-11 15:10:54 -04:00
committed by GitHub
parent 4f2d342649
commit bbfe2a2329
197 changed files with 14668 additions and 27810 deletions
-12
View File
@@ -1,12 +0,0 @@
syntax = "proto3";
package did.v1;
option go_package = "github.com/onsonr/sonr/x/did/types";
message BtcAccount {}
message EthAccount {}
message IBCAccount {}
message SnrAccount {}
+10 -21
View File
@@ -27,20 +27,17 @@ message Params {
// Whitelisted Key Types
repeated KeyInfo allowed_public_keys = 3;
// OpenIDConfig defines the base openid configuration across all did services
OpenIDConfig openid_config = 4;
// IpfsActive is a flag to enable/disable ipfs
bool ipfs_active = 5;
bool ipfs_active = 4;
// Localhost Registration Enabled
bool localhost_registration_enabled = 6;
bool localhost_registration_enabled = 5;
// ConveyancePreference defines the conveyance preference
string conveyance_preference = 7;
string conveyance_preference = 6;
// AttestationFormats defines the attestation formats
repeated string attestation_formats = 8;
repeated string attestation_formats = 7;
}
// AssetInfo defines the asset info
@@ -85,20 +82,6 @@ message KeyInfo {
KeyType type = 5; // e.g., "Octet", "Elliptic", "RSA", "Symmetric", "HMAC"
}
// OpenIDConfig defines the base openid configuration across all did services
message OpenIDConfig {
string issuer = 1;
string authorization_endpoint = 2;
string token_endpoint = 3;
string userinfo_endpoint = 4;
repeated string scopes_supported = 5;
repeated string response_types_supported = 6;
repeated string response_modes_supported = 7;
repeated string grant_types_supported = 8;
repeated string acr_values_supported = 9;
repeated string subject_types_supported = 10;
}
// ValidatorInfo defines information for accepted Validator nodes
message ValidatorInfo {
string moniker = 1;
@@ -221,6 +204,12 @@ enum KeyType {
KEY_TYPE_BIP32 = 9;
}
enum KeyshareRole {
KEYSHARE_ROLE_UNSPECIFIED = 0;
KEYSHARE_ROLE_USER = 1;
KEYSHARE_ROLE_VALIDATOR = 2;
}
// PermissionScope define the Capabilities Controllers can grant for Services
enum PermissionScope {
PERMISSION_SCOPE_UNSPECIFIED = 0;
+55 -74
View File
@@ -7,56 +7,47 @@ import "gogoproto/gogo.proto";
option go_package = "github.com/onsonr/sonr/x/did/types";
// Accumulator defines a BLS accumulator
message Accumulator {
bytes accumulator = 1;
// Alias defines a subject/origin pair
message Alias {
string subject = 1;
string origin = 2;
string controller = 3;
}
// Credential defines a WebAuthn credential
message Credential {
string id = 1;
string credential_type = 2;
bytes credential_id = 3;
repeated string transport = 4;
string subject = 6;
string controller = 7;
}
// DID defines a parsed DID string
message DID {
DIDNamespace method = 1;
string network = 2;
string subject = 3;
string identifier = 4;
repeated string paths = 5;
string subject = 1;
string attestation_type = 2;
string origin = 3;
bytes credential_id = 4;
bytes public_key = 5;
repeated string transport = 6;
uint32 sign_count = 7;
bool user_present = 8;
bool user_verified = 9;
bool backup_eligible = 10;
bool backup_state = 11;
bool clone_warning = 12;
}
// Document defines a DID document
message Document {
string id = 1;
repeated VerificationMethod verification_methods = 2;
repeated string authentication = 4;
repeated string assertion_method = 5;
repeated string capability_delegation = 7;
repeated string capability_invocation = 8;
repeated string service = 9;
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;
}
// JWK represents a JSON Web Key
message JWK {
string kty = 1; // Key Type
string crv = 2; // Curve (for EC and OKP keys)
string x = 3; // X coordinate (for EC and OKP keys)
string y = 4; // Y coordinate (for EC keys)
string n = 5; // Modulus (for RSA keys)
string e = 6; // Exponent (for RSA keys)
}
// Metadata defines additional information provided to a did
message Metadata {
string origin_uri = 1;
map<string, string> public = 2;
map<string, Property> private = 3;
// Keyshare defines a keyshare from the MPC protocol
message Keyshare {
map<string, string> metadata = 1;
map<string, bytes> payloads = 2;
string protocol = 3;
bytes public_key = 4;
uint32 version = 5;
int32 role = 6; // 0 =none, 1 = validator, 2 = user
}
// Permissions contains a list of grants and access control rules for
@@ -66,21 +57,6 @@ message Permissions {
repeated PermissionScope scopes = 2;
}
// Profile defines an associated public identity for a did subject
message Profile {
string id = 1;
string subject = 2;
string controller = 3;
Metadata metadata = 4;
}
// Property defines a Zero-Knowledge accumulator which can be used to
// anonymously prove a given value to a DID subject
message Property {
bytes accumulator = 1;
bytes key = 2;
}
// PubKey defines a public key for a did
message PubKey {
KeyRole role = 1;
@@ -90,16 +66,35 @@ message PubKey {
KeyType key_type = 5;
bytes raw = 6;
JWK jwk = 7;
// JWK represents a JSON Web Key
message JWK {
string kty = 1; // Key Type
string crv = 2; // Curve (for EC and OKP keys)
string x = 3; // X coordinate (for EC and OKP keys)
string y = 4; // Y coordinate (for EC keys)
string n = 5; // Modulus (for RSA keys)
string e = 6; // Exponent (for RSA keys)
}
}
// Service defines a Decentralized Service on the Sonr Blockchain
message Service {
string id = 1;
string controller = 2;
string origin = 3;
Permissions permissions = 4;
OpenIDConfig openid = 5;
Metadata metadata = 6;
string service_type = 2;
string authority = 3;
string origin = 4;
string description = 5;
map<string, string> service_endpoints = 6;
Permissions permissions = 7;
}
// ServicceInfo defines a Decentralized Service on the Sonr Blockchain
message ServiceInfo {
bool exists = 1;
string origin = 2;
string fingerprint = 3;
Service service = 4;
}
// Token defines a macron token
@@ -108,17 +103,3 @@ message Token {
string controller = 2;
bytes macron = 3;
}
// VerificationMethod defines a verification method
message VerificationMethod {
DIDNamespace method = 1;
string id = 2;
string controller = 3;
string issuer = 4;
PubKey public_key = 5;
}
// Witness defines a BLS witness
message Witness {
bytes witness = 1;
}
+9 -43
View File
@@ -4,24 +4,25 @@ package did.v1;
import "did/v1/genesis.proto";
import "did/v1/models.proto";
import "google/api/annotations.proto";
import "google/api/httpbody.proto";
option go_package = "github.com/onsonr/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(QueryRequest) returns (QueryResponse) {
option (google.api.http).get = "/did/params";
}
// Resolve queries the DID document by its id.
rpc Resolve(QueryRequest) returns (QueryResolveResponse) {
rpc Resolve(QueryRequest) returns (QueryResponse) {
option (google.api.http).get = "/did/{did}";
}
// Service returns associated ServiceInfo for a given Origin
rpc Service(QueryRequest) returns (QueryServiceResponse) {
// if the servie is not found, a fingerprint is generated to be used
// as a TXT record in DNS. v=sonr, o=origin, p=protocol
rpc Service(QueryRequest) returns (QueryResponse) {
option (google.api.http).get = "/service/{origin}";
}
}
@@ -30,48 +31,13 @@ service Query {
message QueryRequest {
string did = 1;
string origin = 2;
string subject = 3;
string endpoint = 4;
}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1;
}
// QueryResponse is the response type for the Query/Exists RPC method.
message QueryResponse {
bool success = 1;
string subject = 2;
string origin = 3;
bool ipfs_active = 4;
Params params = 5;
Document document = 6;
Service service = 7;
repeated Credential credentials = 8;
Token token = 9;
string error = 10;
}
// QueryResolveResponse is the response type for the Query/Resolve RPC method.
message QueryResolveResponse {
message QueryResponse {
bool success = 1;
string subject = 2;
string origin = 3;
bool ipfs_active = 4;
string query = 2;
Document document = 3;
ServiceInfo service = 4;
Params params = 5;
Document document = 6;
repeated Credential credentials = 7;
Token token = 8;
}
// QueryLoginOptionsResponse is the response type for the Query/LoginOptions RPC method.
message QueryServiceResponse {
bool success = 1;
string subject = 2;
string origin = 3;
bool ipfs_active = 4;
Params params = 5;
Service service = 6;
}
+74 -97
View File
@@ -8,99 +8,57 @@ import "did/v1/models.proto";
option go_package = "github.com/onsonr/sonr/x/did/types";
// Authentication represents strongly created credentials (e.g., Passkeys, SSH, GPG, Native Secure Enclaave)
message Authentication {
// Account represents a wallet account associated with a DID Controller
message Account {
option (cosmos.orm.v1.table) = {
id: 1
primary_key: {fields: "id"}
index: {
id: 1
fields: "subject,origin"
fields: "controller,label"
unique: true
}
index: {
id: 2
fields: "controller,origin"
fields: "controller,address"
unique: true
}
index: {
id: 3
fields: "controller,credential_label"
fields: "controller,chain_code,index"
unique: true
}
};
// The unique identifier of the attestation
// The unique identifier of the account
string id = 1;
// The controller of the attestation
string controller = 2;
// Key type (e.g., "passkey", "ssh", "gpg", "native-secure-enclave")
PubKey public_key = 3;
// The origin of the attestation
string origin = 4;
// The subject of the attestation
string subject = 5;
// The value of the linked identifier
bytes credential_id = 6;
// The credential label
string credential_label = 7;
// The display label of the attestation
repeated string credential_transport = 8;
// The attestationtype of the attestation
string attestation_type = 9;
// Metadata is optional additional information about the assertion
Metadata metadata = 10;
}
// Assertion represents linked identifiers (e.g., Crypto Accounts, Github, Email, Phone)
message Assertion {
option (cosmos.orm.v1.table) = {
id: 2
primary_key: {fields: "id"}
index: {
id: 1
fields: "subject,origin"
unique: true
}
index: {
id: 2
fields: "controller,origin"
unique: true
}
};
// The unique identifier of the attestation
string id = 1;
// The type of the linked identifier (e.g., "crypto", "github", "email", "phone")
// The controller of the account
string controller = 2;
// The value of the linked identifier
PubKey public_key = 3;
// The origin of the attestation
string origin = 4;
// The address of the account
string address = 4;
// The subject of the attestation
string subject = 5;
// The label of the account
string label = 5;
// The controller of the attestation
Metadata metadata = 6;
// The bip32 chain code
uint32 chain_code = 6;
// The index of the account
uint32 index = 7;
// The supported chains of the account
repeated string chains = 8;
}
// Controller represents a Sonr DWN Vault
message Controller {
option (cosmos.orm.v1.table) = {
id: 3
id: 2
primary_key: {fields: "id"}
index: {
id: 1
@@ -121,71 +79,62 @@ message Controller {
string address = 2;
// Aliases of the controller
repeated string aliases = 3;
repeated Alias aliases = 3;
// PubKey is the verification method
PubKey public_key = 4;
// The vault address or identifier
string vault_cid = 5;
// The Authentications of the controller
repeated Credential authentication = 6;
}
// Delegation represents IBC Account Controllers for various chains (e.g., ETH, BTC)
message Delegation {
// Proof represents a verifiable credential
message Proof {
option (cosmos.orm.v1.table) = {
id: 4
primary_key: {fields: "id"}
index: {
id: 1
fields: "account_address,chain_id"
fields: "controller,issuer,property"
unique: true
}
index: {
id: 2
fields: "controller,account_label"
unique: true
}
index: {
id: 3
fields: "controller,chain_id"
}
};
// The unique identifier of the delegation
// The unique identifier of the proof
string id = 1;
// The Decentralized Identifier of the delegated account
// The controller of the proof
string controller = 2;
// Resolved from module parameters
string chain_index = 3;
// The value of the linked identifier
string issuer = 3;
// The delegation proof or verification method
PubKey public_key = 4;
// The property of the proof
string property = 4;
// The Account Address
string account_address = 5;
// The accumulator of the proof
bytes accumulator = 5;
// The Account label
string account_label = 6;
// The Chain ID
string chain_id = 7;
// The secret key of the proof
bytes key = 6;
}
// ServiceRecord represents a decentralized service in a DID Document
message ServiceRecord {
option (cosmos.orm.v1.table) = {
id: 5
id: 3
primary_key: {fields: "id"}
index: {
id: 1
fields: "origin_uri"
fields: "origin"
unique: true
}
index: {
id: 2
fields: "controller,origin_uri"
fields: "authority,origin"
unique: true
}
};
@@ -196,11 +145,11 @@ message ServiceRecord {
// The type of the service
string service_type = 2;
// The controller DID of the service
string controller = 3;
// The authority DID of the service
string authority = 3;
// The domain name of the service
string origin_uri = 4;
string origin = 4;
// The description of the service
string description = 5;
@@ -210,7 +159,35 @@ message ServiceRecord {
// Scopes is the Authorization Grants of the service
Permissions permissions = 7;
// Metadata is optional additional information about the service
Metadata metadata = 8;
}
// Verification reprsents a method of verifying membership in a DID
message VerificationMethod {
option (cosmos.orm.v1.table) = {
id: 5
primary_key: {fields: "id"}
index: {
id: 1
fields: "controller,method,issuer,subject"
unique: true
}
};
// The unique identifier of the verification
string id = 1;
// The controller of the verification
string controller = 2;
// The DIDNamespace of the verification
DIDNamespace method = 3;
// The value of the linked identifier
string issuer = 4;
// The subject of the verification
string subject = 5;
// The public key of the verification
PubKey public_key = 6;
}
+26 -41
View File
@@ -18,15 +18,15 @@ service Msg {
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// Authorize asserts the given controller is the owner of the given address.
rpc Authorize(MsgAuthorize) returns (MsgAuthorizeResponse);
// AuthorizeService asserts the given controller is the owner of the given address.
rpc AuthorizeService(MsgAuthorizeService) returns (MsgAuthorizeServiceResponse);
// AllocateVault assembles a sqlite3 database in a local directory and returns the CID of the database.
// this operation is called by services initiating a controller registration.
rpc AllocateVault(MsgAllocateVault) returns (MsgAllocateVaultResponse);
// SyncVault synchronizes the controller with the Vault Motr DWN WASM Wallet.
rpc SyncVault(MsgSyncVault) returns (MsgSyncVaultResponse);
// SyncController synchronizes the controller with the Vault Motr DWN WASM Wallet.
rpc SyncController(MsgSyncController) returns (MsgSyncControllerResponse);
// RegisterController initializes a controller with the given authentication set, address, cid, publicKey, and user-defined alias.
rpc RegisterController(MsgRegisterController) returns (MsgRegisterControllerResponse);
@@ -81,6 +81,9 @@ message MsgAllocateVaultResponse {
// RegistrationOptions is a json string of the PublicKeyCredentialCreationOptions for WebAuthn
string registration_options = 3;
// IsLocalhost is a flag to indicate if the vault is localhost
bool localhost = 4;
}
// MsgProveWitness is the message type for the ProveWitness RPC.
@@ -106,8 +109,8 @@ message MsgProveWitnessResponse {
string property = 2;
}
// MsgSyncVault is the message type for the SyncVault RPC.
message MsgSyncVault {
// MsgSyncController is the message type for the SyncController RPC.
message MsgSyncController {
option (cosmos.msg.v1.signer) = "controller";
// controller is the address of the controller to sync.
@@ -117,8 +120,8 @@ message MsgSyncVault {
Token token = 3;
}
// MsgSyncVaultResponse is the response type for the SyncVault RPC.
message MsgSyncVaultResponse {
// MsgSyncControllerResponse is the response type for the SyncController RPC.
message MsgSyncControllerResponse {
bool success = 1;
}
@@ -136,10 +139,7 @@ message MsgRegisterController {
string origin = 3;
// Credential is the list of keyshares to initialize the controller with.
repeated Credential authentication = 4;
// token is the macron token to authenticate the operation.
Token token = 5;
string credential_creation_response = 4;
}
// MsgRegisterControllerResponse is the response type for the InitializeController RPC.
@@ -154,28 +154,25 @@ message MsgRegisterControllerResponse {
map<string, string> accounts = 3;
}
// MsgAuthorize is the message type for the Authorize RPC.
message MsgAuthorize {
option (cosmos.msg.v1.signer) = "authority";
// authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// MsgAuthorizeService is the message type for the AuthorizeService RPC.
message MsgAuthorizeService {
option (cosmos.msg.v1.signer) = "controller";
// Controller is the address of the controller to authenticate.
string controller = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Address is the address to authenticate.
string address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Origin is the origin of the request in wildcard form.
string origin = 4;
string origin = 2;
// Permissions is the scope of the service.
Permissions scopes = 3;
// token is the macron token to authenticate the operation.
Token token = 5;
Token token = 4;
}
// MsgAuthorizeResponse is the response type for the Authorize RPC.
message MsgAuthorizeResponse {
// MsgAuthorizeServiceResponse is the response type for the AuthorizeService RPC.
message MsgAuthorizeServiceResponse {
bool success = 1;
Token token = 2;
}
@@ -187,23 +184,11 @@ message MsgRegisterService {
// authority is the address of the governance account.
string controller = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// origin is the origin of the request in wildcard form.
string origin_uri = 2;
// Permissions is the scope of the service.
Permissions scopes = 3;
// Description is the description of the service
string description = 4;
// service_endpoints is the endpoints of the service
map<string, string> service_endpoints = 5;
// Metadata is optional additional information about the service
Metadata metadata = 6;
// origin is the origin of the request in wildcard form. Requires valid TXT record in DNS.
Service service = 2;
// token is the macron token to authenticate the operation.
Token token = 7;
Token token = 3;
}
// MsgRegisterServiceResponse is the response type for the RegisterService RPC.
-13
View File
@@ -1,13 +0,0 @@
syntax = "proto3";
package onsonr.sonr.oracle.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/onsonr/sonr"
};
}
-10
View File
@@ -1,10 +0,0 @@
syntax = "proto3";
package oracle.v1;
option go_package = "github.com/onsonr/sonr/x/oracle/types";
import "gogoproto/gogo.proto";
// GenesisState defines the middlewares genesis state.
message GenesisState {}
-7
View File
@@ -1,7 +0,0 @@
syntax = "proto3";
package oracle.v1;
option go_package = "github.com/onsonr/sonr/x/oracle/types";
import "gogoproto/gogo.proto";
-7
View File
@@ -1,7 +0,0 @@
syntax = "proto3";
package oracle.v1;
option go_package = "github.com/onsonr/sonr/x/oracle/types";
import "gogoproto/gogo.proto";