Skip to content

Latest commit

 

History

History
1739 lines (771 loc) · 58.1 KB

File metadata and controls

1739 lines (771 loc) · 58.1 KB

Module 0x3::did

Struct DID

DID identifier type

struct DID has copy, drop, store

Struct VerificationMethodID

Verification method ID

struct VerificationMethodID has copy, drop, store

Struct ServiceID

Service ID

struct ServiceID has copy, drop, store

Struct VerificationMethod

Verification method

struct VerificationMethod has copy, drop, store

Struct Service

Service definition

struct Service has copy, drop, store

Resource DIDDocument

DID Document containing all DID information. This is the data part of an Object. The DIDDocuemnt only has key ability, no store, so the user can not transfer it to other accounts.

struct DIDDocument has key

Resource DIDRegistry

Registry to store mappings. This is a Named Object.

struct DIDRegistry has key

Struct DIDCreatedEvent

Event emitted when a new DID document is created

#[event]
struct DIDCreatedEvent has copy, drop, store

Struct VerificationMethodAddedEvent

Event emitted when a verification method is added to a DID document

#[event]
struct VerificationMethodAddedEvent has copy, drop, store

Struct VerificationMethodRemovedEvent

Event emitted when a verification method is removed from a DID document

#[event]
struct VerificationMethodRemovedEvent has copy, drop, store

Struct VerificationRelationshipModifiedEvent

Event emitted when a verification relationship is modified

#[event]
struct VerificationRelationshipModifiedEvent has copy, drop, store

Struct ServiceAddedEvent

Event emitted when a service is added to a DID document

#[event]
struct ServiceAddedEvent has copy, drop, store

Struct ServiceUpdatedEvent

Event emitted when a service is updated in a DID document

#[event]
struct ServiceUpdatedEvent has copy, drop, store

Struct ServiceRemovedEvent

Event emitted when a service is removed from a DID document

#[event]
struct ServiceRemovedEvent has copy, drop, store

Constants

The format of the publicKeyMultibase string is invalid or cannot be parsed

Invalid signature (can be reused or made more specific)

const ErrorInvalidSignature: u64 = 11;

Associated AccountCap not found in DIDDocument when expected

const ErrorAccountCapNotFound: u64 = 14;

did:bitcoin address does not match provided public key

Controller DID method is not supported

Missing user VM info for non did:key controller

Permission denied based on controller check

Custodian DID document does not exist

const ErrorCustodianDIDNotFound: u64 = 30;

Custodian does not have CADOP service

DID already exists (e.g., identifier already registered)

const ErrorDIDAlreadyExists: u64 = 2;

DID document does not exist (legacy or general not found)

const ErrorDIDDocumentNotExist: u64 = 1;

For did:key controllers, the initial verification method public key must match the key in the DID identifier

DID Object not found for the given identifier

const ErrorDIDObjectNotFound: u64 = 13;

DIDRegistry is already initialized

Fragment string is too long

const ErrorFragmentTooLong: u64 = 41;

Verification method has insufficient permission for the requested operation

const ErrorInsufficientPermission: u64 = 26;

Generic invalid argument

const ErrorInvalidArgument: u64 = 17;

Invalid DID string format (should be "did:method:identifier")

const ErrorInvalidDIDStringFormat: u64 = 22;

Invalid VM type for the specified controller

Invalid verification relationship

Multiple did:key controllers are not allowed during initial DID creation with a did:key controller

No controllers specified during DID creation or update

const ErrorNoControllersSpecified: u64 = 18;

No session key found in transaction context - all DID operations must use session keys

const ErrorNoSessionKeyInContext: u64 = 28;

Mismatch in length between property keys and values for a service

Service already exists

const ErrorServiceAlreadyExists: u64 = 7;

Service not found

const ErrorServiceNotFound: u64 = 6;

Session key not found in DID document's authentication methods

const ErrorSessionKeyNotFound: u64 = 25;

Failed to register key with the Rooch session key module

The signer is not the DID's associated account

const ErrorSignerNotDIDAccount: u64 = 27;

String field is too long

const ErrorStringTooLong: u64 = 42;

Exceeded maximum number of also known as aliases

const ErrorTooManyAlsoKnownAs: u64 = 39;

Exceeded maximum number of controllers

const ErrorTooManyControllers: u64 = 40;

Exceeded maximum number of verification methods allowed in a relationship

Exceeded maximum number of properties allowed per service

Exceeded maximum number of services allowed in a DID document

const ErrorTooManyServices: u64 = 37;

Exceeded maximum number of verification methods allowed in a DID document

Unauthorized operation (generic, consider specific ErrorControllerPermissionDenied)

const ErrorUnauthorized: u64 = 3;

Verification method type is not supported for Rooch session key linkage (e.g., not Ed25519)

Verification method already exists

Verification method has expired

Verification method not found

Verification method not in the relationship

const MAX_FRAGMENT_LENGTH: u64 = 128;

const MAX_PROPERTIES_PER_SERVICE: u64 = 16;

const MAX_SERVICES_PER_DOCUMENT: u64 = 32;

const MAX_STRING_LENGTH: u64 = 512;

const VERIFICATION_METHOD_TYPE_ED25519: vector<u8> = [69, 100, 50, 53, 53, 49, 57, 86, 101, 114, 105, 102, 105, 99, 97, 116, 105, 111, 110, 75, 101, 121, 50, 48, 50, 48];

const VERIFICATION_METHOD_TYPE_SECP256K1: vector<u8> = [69, 99, 100, 115, 97, 83, 101, 99, 112, 50, 53, 54, 107, 49, 86, 101, 114, 105, 102, 105, 99, 97, 116, 105, 111, 110, 75, 101, 121, 50, 48, 49, 57];

const VERIFICATION_METHOD_TYPE_SECP256R1: vector<u8> = [69, 99, 100, 115, 97, 83, 101, 99, 112, 50, 53, 54, 114, 49, 86, 101, 114, 105, 102, 105, 99, 97, 116, 105, 111, 110, 75, 101, 121, 50, 48, 49, 57];

Function verification_relationship_authentication

Get verification relationship constant for authentication

Function verification_relationship_assertion_method

Get verification relationship constant for assertion method

Function verification_relationship_capability_invocation

Get verification relationship constant for capability invocation

Function verification_relationship_capability_delegation

Get verification relationship constant for capability delegation

Function verification_relationship_key_agreement

Get verification relationship constant for key agreement

Function verification_method_type_ed25519

Get verification method type constant for Ed25519

Function verification_method_type_secp256k1

Get verification method type constant for Secp256k1

Function verification_method_type_secp256r1

Get verification method type constant for Secp256r1

Function verify_signature_by_type

Verify a signature using the specified verification method type and public key. This is a generic signature verification function that can be used across different modules.

public fun verify_signature_by_type(message: vector<u8>, signature: vector<u8>, public_key_multibase: &string::String, method_type: &string::String): bool

Function genesis_init

public(friend) fun genesis_init()

Function init_did_registry

Initialize the DID system Any account can call this function to initialize the DID system

public entry fun init_did_registry()

Function create_did_object_for_self_entry

Create a DID for oneself using account key only. This function validates that the provided public key corresponds to the creator's account. Currently only supports Secp256k1 keys.

public entry fun create_did_object_for_self_entry(creator_account_signer: &signer, account_public_key_multibase: string::String)

Function create_did_object_for_self

Internal function for self DID creation. Validates that the provided public key matches the creator's account address.

public fun create_did_object_for_self(creator_account_signer: &signer, account_public_key_multibase: string::String): object::ObjectID

Function create_did_object_for_self_with_custom_scopes_entry

Create a DID for oneself with custom session key scopes

public entry fun create_did_object_for_self_with_custom_scopes_entry(creator_account_signer: &signer, account_public_key_multibase: string::String, session_scope_strings: vector<string::String>)

Function create_did_object_for_self_with_custom_scopes

Internal function for self DID creation with custom scopes

public fun create_did_object_for_self_with_custom_scopes(creator_account_signer: &signer, account_public_key_multibase: string::String, custom_session_scope_strings: option::Option<vector<string::String>>): object::ObjectID

Function create_did_object_via_cadop_with_did_key_entry

Create a DID via CADOP (Custodian-Assisted DID Onboarding Protocol) using did:key. The custodian assists in DID creation but the user retains control. Each user gets a unique service key from the custodian. The user's public key is extracted from their did:key string. Backward-compatible non-scope entry; delegates to scoped version with default scopes.

public entry fun create_did_object_via_cadop_with_did_key_entry(custodian_signer: &signer, user_did_key_string: string::String, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String)

Function create_did_object_via_cadop_with_did_key_and_scopes_entry

Create a DID Object via CADOP with did:key and custom session key scopes This function allows custodians to create DID objects with customized scope permissions

Arguments

  • custodian_signer - Custodian's Rooch account, pays gas
  • user_did_key_string - User's did:key string (e.g., "did:key:zABC...")
  • custodian_service_pk_multibase - Custodian's service public key for this user
  • custodian_service_vm_type - Custodian service VM type (Ed25519 or Secp256k1)
  • custom_scope_strings - Vector of custom scope strings in format "address::module::function"
public entry fun create_did_object_via_cadop_with_did_key_and_scopes_entry(custodian_signer: &signer, user_did_key_string: string::String, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String, custom_scope_strings: vector<string::String>)

Function create_did_object_via_cadop_with_did_key

Internal function for CADOP DID creation with did:key. Returns the ObjectID of the created DID document for testing and verification. Backward-compatible non-scope internal; delegates to scoped version with default scopes.

public fun create_did_object_via_cadop_with_did_key(custodian_signer: &signer, user_did_key_string: string::String, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String): object::ObjectID

Function create_did_object_via_cadop_with_did_key_and_scopes

Internal function for CADOP DID creation with did:key and custom scopes. Returns the ObjectID of the created DID document for testing and verification.

Arguments

  • custodian_signer - Custodian's Rooch account, pays gas
  • user_did_key_string - User's did:key string (e.g., "did:key:zABC...")
  • custodian_service_pk_multibase - Custodian's service public key for this user
  • custodian_service_vm_type - Custodian service VM type (Ed25519 or Secp256k1)
  • custom_scope_strings - Optional vector of custom scope strings in format "address::module::function"
public fun create_did_object_via_cadop_with_did_key_and_scopes(custodian_signer: &signer, user_did_key_string: string::String, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String, custom_scope_strings: option::Option<vector<string::String>>): object::ObjectID

Function create_did_object_via_cadop_with_controller_and_scopes_entry

New entry: Create a DID Object via CADOP with arbitrary controller DID and custom scopes. Supports did:key and did:bitcoin (future did:ethereum can be added similarly).

public entry fun create_did_object_via_cadop_with_controller_and_scopes_entry(custodian_signer: &signer, controller_did_string: string::String, user_vm_pk_multibase: string::String, user_vm_type: string::String, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String, custom_scope_strings: vector<string::String>)

Function create_did_object_via_cadop_with_controller_and_scopes

Internal: controller-based CADOP DID creation with custom scopes. Controller can be did:key (auto-extract VM) or did:bitcoin (require VM pk/type and verify).

public fun create_did_object_via_cadop_with_controller_and_scopes(custodian_signer: &signer, controller_did_string: string::String, user_vm_pk_multibase_opt: option::Option<string::String>, user_vm_type_opt: option::Option<string::String>, custodian_service_pk_multibase: string::String, custodian_service_vm_type: string::String, custom_scope_strings: option::Option<vector<string::String>>): object::ObjectID

Function add_verification_method_entry

public entry fun add_verification_method_entry(did_signer: &signer, fragment: string::String, method_type: string::String, public_key_multibase: string::String, verification_relationships: vector<u8>)

Function add_verification_method_with_scopes_entry

public entry fun add_verification_method_with_scopes_entry(did_signer: &signer, fragment: string::String, method_type: string::String, public_key_multibase: string::String, verification_relationships: vector<u8>, custom_session_scope: vector<string::String>)

Function remove_verification_method_entry

public entry fun remove_verification_method_entry(did_signer: &signer, fragment: string::String)

Function add_to_verification_relationship_entry

public entry fun add_to_verification_relationship_entry(did_signer: &signer, fragment: string::String, relationship_type: u8)

Function add_to_verification_relationship_with_scope_entry

public entry fun add_to_verification_relationship_with_scope_entry(did_signer: &signer, fragment: string::String, relationship_type: u8, custom_session_scope: vector<string::String>)

Function remove_from_verification_relationship_entry

public entry fun remove_from_verification_relationship_entry(did_signer: &signer, fragment: string::String, relationship_type: u8)

Function add_service_entry

public entry fun add_service_entry(did_signer: &signer, fragment: string::String, service_type: string::String, service_endpoint: string::String)

Function add_service_with_properties_entry

public entry fun add_service_with_properties_entry(did_signer: &signer, fragment: string::String, service_type: string::String, service_endpoint: string::String, property_keys: vector<string::String>, property_values: vector<string::String>)

Function update_service_entry

public entry fun update_service_entry(did_signer: &signer, fragment: string::String, new_service_type: string::String, new_service_endpoint: string::String, new_property_keys: vector<string::String>, new_property_values: vector<string::String>)

Function remove_service_entry

public entry fun remove_service_entry(did_signer: &signer, fragment: string::String)

Function exists_did_document_by_identifier

public fun exists_did_document_by_identifier(identifier_str: string::String): bool

Function exists_did_for_address

public fun exists_did_for_address(addr: address): bool

Function get_dids_by_controller

Get all DID ObjectIDs controlled by a specific controller DID

public fun get_dids_by_controller(controller_did: did::DID): vector<string::String>

Function get_dids_by_controller_string

Function has_verification_relationship_in_doc

public fun has_verification_relationship_in_doc(did_document_data: &did::DIDDocument, fragment: &string::String, relationship_type: u8): bool

Function is_verification_method_valid_in_doc

public fun is_verification_method_valid_in_doc(did_document_data: &did::DIDDocument, fragment: &string::String): bool

Function format_did

Function format_verification_method_id

Function format_service_id

Function new_did_from_parts

Create a DID struct from method and identifier parts This function only constructs a DID struct, it does NOT create a DID object on-chain

public fun new_did_from_parts(method: string::String, identifier: string::String): did::DID

Function new_rooch_did_by_address

Create a Rooch DID struct from an address This function only constructs a DID struct, it does NOT create a DID object on-chain

public fun new_rooch_did_by_address(addr: address): did::DID

Function parse_did_string

Parse a DID string in the format "did:method:identifier" into a DID struct

public fun parse_did_string(did_string: &string::String): did::DID

Function get_did_identifier_string

Get the identifier from a DID

Function get_did_method

Get the method from a DID

Function get_did_document

Function get_did_document_by_address

Get DIDDocument by address

public fun get_did_document_by_address(addr: address): &did::DIDDocument

Function get_did_document_by_object_id

Get DIDDocument by ObjectID

Function doc_id

Get id from DIDDocument

public fun doc_id(did_doc: &did::DIDDocument): &did::DID

Function doc_controllers

Get controllers from DIDDocument

Function doc_verification_methods

Get verification methods from DIDDocument

Function doc_verification_method

Get verification method by fragment

Function verification_method_id

Function verification_method_type

Function verification_method_controller

Function verification_method_public_key_multibase

Function doc_authentication_methods

Get authentication methods from DIDDocument

Function doc_assertion_methods

Get assertion methods from DIDDocument

Function doc_capability_invocation_methods

Get capability invocation methods from DIDDocument

Function doc_capability_delegation_methods

Get capability delegation methods from DIDDocument

Function doc_key_agreement_methods

Get key agreement methods from DIDDocument

Function doc_services

Get services from DIDDocument

Function doc_service

Get service by fragment

Function service_id

public fun service_id(service: &did::Service): &did::ServiceID

Function service_type

public fun service_type(service: &did::Service): &string::String

Function service_endpoint

Function service_properties

Function doc_also_known_as

Get also known as from DIDDocument

Function get_created_timestamp_by_object_id

Get created timestamp from Object system This accesses the Object's metadata created_at timestamp

Function get_updated_timestamp_by_object_id

Get updated timestamp from Object system This accesses the Object's metadata updated_at timestamp

Function get_did_address

public fun get_did_address(did_doc: &did::DIDDocument): address

Function find_verification_method_by_session_key

Find the verification method fragment that corresponds to the given session key Returns None if no matching verification method is found