sonr/x/did/README.md

174 lines
5.2 KiB
Markdown
Raw Permalink Normal View History

2024-07-05 22:20:13 -04:00
# `x/did`
The Decentralized Identity module is responsible for managing native Sonr Accounts, their derived wallets, and associated user identification information. This module now incorporates UCAN (User Controlled Authorization Networks) for enhanced authorization and access control.
2024-07-05 22:20:13 -04:00
## State
2024-10-21 16:59:29 -04:00
The DID module maintains several key state structures:
### Controller State
The Controller state represents a Sonr DWN Vault. It includes:
2024-10-21 16:59:29 -04:00
- Unique identifier (number)
- DID
- Sonr address
- Ethereum address
- Bitcoin address
- Public key
- Keyshares pointer
- Claimed block
- Creation block
### Assertion State
The Assertion state includes:
2024-10-21 16:59:29 -04:00
- DID
- Controller
- Subject
- Public key
- Assertion type
- Accumulator (metadata)
- Creation block
### Authentication State
The Authentication state includes:
2024-10-21 16:59:29 -04:00
- DID
- Controller
- Subject
- Public key
- Credential ID
- Metadata
- Creation block
### Verification State
The Verification state includes:
2024-10-21 16:59:29 -04:00
- DID
- Controller
- DID method
- Issuer
- Subject
- Public key
- Verification type
- Metadata
- Creation block
2024-07-05 22:20:13 -04:00
## State Transitions
2024-10-21 16:59:29 -04:00
State transitions are triggered by the following messages:
2024-10-21 16:59:29 -04:00
- LinkAssertion
- LinkAuthentication
- UnlinkAssertion
- UnlinkAuthentication
- ExecuteTx
- UpdateParams
2024-07-05 22:20:13 -04:00
## Messages
2024-10-21 16:59:29 -04:00
The DID module defines the following messages:
2024-07-05 22:20:13 -04:00
2024-10-21 16:59:29 -04:00
1. MsgLinkAuthentication
2. MsgLinkAssertion
3. MsgExecuteTx
4. MsgUnlinkAssertion
5. MsgUnlinkAuthentication
6. MsgUpdateParams
2024-07-05 22:20:13 -04:00
Each message triggers specific state machine behaviors related to managing DIDs, authentications, assertions, and module parameters. These messages now also involve UCAN authorization checks where applicable.
2024-07-05 22:20:13 -04:00
2024-10-21 16:59:29 -04:00
## Query
2024-07-05 22:20:13 -04:00
2024-10-21 16:59:29 -04:00
The DID module provides the following query endpoints:
2024-07-05 22:20:13 -04:00
1. Params: Query all parameters of the module, including UCAN-related parameters.
2024-10-21 16:59:29 -04:00
2. Resolve: Query the DID document by its ID
3. Sign: Sign a message with the DID document
4. Verify: Verify a message with the DID document
2024-07-05 22:20:13 -04:00
2024-10-21 16:59:29 -04:00
## Params
2024-07-05 22:20:13 -04:00
2024-10-21 16:59:29 -04:00
The module parameters include:
2024-10-21 16:59:29 -04:00
- Allowed public keys (map of KeyInfo)
- Conveyance preference
- Attestation formats
- UCAN Authorization Parameters:
- `UcanPermissions`: Specifies the required UCAN permissions for various actions within the module.
2024-07-05 22:20:13 -04:00
## Client
2024-10-21 16:59:29 -04:00
The module provides gRPC and REST endpoints for all defined messages and queries.
2024-07-05 22:20:13 -04:00
## UCAN Authorization
This module utilizes UCAN (User Controlled Authorization Networks) to provide a decentralized and user-centric authorization mechanism. UCANs are self-contained authorization tokens that allow users to delegate specific capabilities to other entities without relying on a central authority.
### UCAN Integration
- The module parameters include a `UcanPermissions` field that defines the default UCAN permissions required for actions within the module.
- Message handlers in the `MsgServer` perform UCAN authorization checks by:
- Retrieving the UCAN permissions from the context (injected by a middleware).
- Retrieving the required UCAN permissions from the module parameters.
- Verifying that the provided UCAN permissions satisfy the required permissions.
- A dedicated middleware is responsible for:
- Parsing incoming requests for UCAN tokens.
- Verifying UCAN token signatures and validity.
- Extracting UCAN permissions.
- Injecting UCAN permissions into the context.
- UCAN verification logic involves:
- Checking UCAN token signatures against the issuer's public key (resolved via the `x/did` module).
- Validating token expiration and other constraints.
- Parsing token capabilities and extracting relevant permissions.
2024-07-05 22:20:13 -04:00
## Future Improvements
2024-10-21 16:59:29 -04:00
Potential future improvements could include:
1. Enhanced privacy features for DID operations, potentially leveraging UCAN capabilities for privacy-preserving authorization.
2024-10-21 16:59:29 -04:00
2. Integration with more blockchain networks
3. Support for additional key types and cryptographic algorithms
4. Improved revocation mechanisms for credentials, assertions, and UCAN tokens.
2024-07-05 22:20:13 -04:00
## Tests
2024-10-21 16:59:29 -04:00
Acceptance tests should cover all major functionality, including:
2024-10-21 16:59:29 -04:00
- Creating and managing DIDs
- Linking and unlinking assertions and authentications
- Executing transactions with DIDs
- Querying and resolving DIDs
- Parameter updates
2024-07-05 22:20:13 -04:00
## Appendix
feature/1129 integrate webauthn controller (#1135) * **refactor: remove nebula static file serving** * **feat: Add login, register, and authorize sections** * **feat: implement registration form UI** * **refactor: abstract template rendering to ctx module** * **feat: add deployment target for Highway gateway** * **feat: migrate Highway gateway to Cloudflare Workers** * **feat: refactor nebula routes to components** * **chore(deps): remove unused dependencies** * **chore(deps): remove unused dependencies** * **feat: add user and relaying party entities** * **refactor: remove unused imports** * * **feat: add motion scale-in and opacity-in animations** * **refactor: move dwn and orm packages to internal** * **refactor: update imports to use relative paths** * **refactor: rename build targets for clarity** * **feat: add RelayingPartyEntity model** * **refactor: rename creds templates to credentials** * **refactor: remove unused entity model** * **refactor: move models to internal package** * **refactor: move models package to internal/orm** * **feat: implement broadcast channel context** * **feat: remove config upload step** * **feat: remove unused configuration files** * **feat: migrate authentication logic to workers** * **feat: remove cloudflared dependency** * **refactor: move client related routes to 'routes/client.go'** * **feat: implement macaroon middleware** * **refactor: move fetch package to cmd/motr** * **feat: remove auth and grant endpoints** * **docs: add conceptual descriptions to did module** <sub><a href="https://huly.app/guest/sonrhq?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsaW5rSWQiOiI2NzA4MTIyNmM3ZDZhNTZhOGY4ZGFjOTciLCJndWVzdCI6InRydWUiLCJlbWFpbCI6IiNndWVzdEBoYy5lbmdpbmVlcmluZyIsIndvcmtzcGFjZSI6InctcHJhZC1zb25yaHEtNjVlZjcyZDQtY2UyOGQ0ODJjNi00ZWY4ZDAifQ.j-w5jk5Ji-0vCkaxVaK8pDMIOhRsXmG7o6oZictoHYE">Huly&reg;: <b>ENG-1057</b></a></sub>
2024-10-10 13:44:17 -04:00
### Account
An Account represents a user's identity within the Sonr ecosystem. It includes information such as the user's public key, associated wallets, and other identification details.
### Decentralized Identifier (DID)
A Decentralized Identifier (DID) is a unique identifier that is created, owned, and controlled by the user. It is used to establish a secure and verifiable digital identity.
### Verifiable Credential (VC)
A Verifiable Credential (VC) is a digital statement that can be cryptographically verified. It contains claims about a subject (e.g., a user) and is issued by a trusted authority.
2024-10-21 16:59:29 -04:00
### Key Types
The module supports various key types, including:
2024-10-21 16:59:29 -04:00
- Role
- Algorithm (e.g., ES256, EdDSA, ES256K)
- Encoding (e.g., hex, base64, multibase)
- Curve (e.g., P256, P384, P521, X25519, X448, Ed25519, Ed448, secp256k1)
### JSON Web Key (JWK)
The module supports JSON Web Keys (JWK) for representing cryptographic keys, including properties such as key type (kty), curve (crv), and coordinates (x, y) for EC and OKP keys, as well as modulus (n) and exponent (e) for RSA keys.