A smart contract implemented in Rust for the NEAR Protocol that functions as a decentralized identifier (DID) registry. It allows ownership management, delegation, attribute assignment, and nonce tracking for DIDs represented by base58-encoded Ed25519 public keys.
-
Signature Algorithm: Ed25519 (used externally for signing/verifying JWTs)
-
Key Encoding:
- Base58 encoding for public keys in
did:near:<base58>
format - Base64url encoding in JWT proofs
- Base58 encoding for public keys in
-
Hashing and Storage: Data keys are tuples of strings and
Vec<u8>
, stored usingLookupMap
fromnear_sdk
- Each identity is a
String
(base58 public key or NEAR account). - Delegates and attributes are valid for a given duration (in seconds).
- Only the current owner of an identity can modify its state.
Field | Description |
---|---|
owners |
Maps identity to current owner (also a String ) |
delegates |
Maps (identity, type, delegate) to expiration |
attributes |
Maps (identity, name, value) to expiration |
changed |
Maps identity to block height of last change |
nonce |
Monotonic counter for off-chain use (signatures) |
Returns the current owner of a DID. Defaults to self-owned if not registered.
Changes the owner of a DID. Only callable by current owner.
Registers a delegate for a DID, valid for the given duration.
Revokes a delegate by setting expiration to 0
.
Returns true
if the delegate is still valid.
Assigns an attribute (e.g. public key, service endpoint) to a DID.
Revokes an attribute by setting its expiration to 0
.
Returns true
if the attribute is still valid.
Returns the current nonce of the identity.
Increments the nonce by 1. Useful for signed interactions.
Returns the block height of the last change made to the identity.
Replace
your-contract.testnet
andidentity
accordingly.
curl -X POST https://rpc.testnet.near.org \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"id": "dontcare",
"method": "query",
"params": {
"request_type": "call_function",
"finality": "final",
"account_id": "your-contract.testnet",
"method_name": "identity_owner",
"args_base64": "eyJpZGVudGl0eSI6ICJkaWQ6bmVhcjpDaGVjaw=="
}
}'
args_base64
is the base64-encoded JSON:{ "identity": "did:near:Check" }
near call your-contract.testnet change_owner '{"identity": "did:near:Check", "new_owner": "did:near:NewKey"}' --accountId your-account.testnet
near call your-contract.testnet add_delegate '{"identity": "did:near:Check", "delegate_type": "veriKey", "delegate": "did:near:OtherKey", "validity_secs": 3600}' --accountId your-account.testnet
near call your-contract.testnet revoke_attribute '{"identity": "did:near:Check", "name": "did/pub/Ed25519/veriKey/base64", "value": "a2V5VmFsdWU="}' --accountId your-account.testnet
value
should be base64-encoded.
{
"@context": "https://w3id.org/did/v1",
"id": "did:near:CF5Ri...",
"verificationMethod": [
{
"id": "did:near:CF5Ri...#owner",
"type": "Ed25519VerificationKey2018",
"controller": "did:near:CF5Ri...",
"publicKeyBase58": "CF5RiJYh4EVmEt8UAD..."
}
],
"authentication": ["did:near:CF5Ri...#owner"],
"assertionMethod": ["did:near:CF5Ri...#owner"]
}
- Designed for interoperability with
did-jwt
,JwtProof2020
, and NEAR-based wallets. - Suitable for creating lightweight DID registries using only Ed25519 keys.
- Compatible with
did:near:<base58PublicKey>
and optionallyexample.testnet
as identity.