IoTeX DID contract implements the functionality of DID registrations. It associates every IoTeX account with a unique decentralized identifier and a corresponding DID document. Every IoTeX account can only register one DID for itself. It is required that the registerer provides the DID document URI where its document can be accessed and the current document hash that represents the initial state of the document. Here is a draft DID registry implementation:
// For reference only and subject to changestring constant didPrefix ="did:io:";struct DID { bool exist; bytes32 hash; string uri;}mapping(string =>DID) dids;functioncreateDID(string id, bytes32 hash, string uri) publicreturns (string) {if (bytes(id).length>0) {require(compareStrings(id,addrToString(msg.sender)),"id does not match creator"); } string memory resultDID =generateDIDString();require(!dids[resultDID].exist,"did already exists"); dids[resultDID] =DID(true, hash, uri);return resultDID;}functiongenerateDIDString() privateviewreturns (string) {returnstring(abi.encodePacked(didPrefix,addrToString(msg.sender)));}
Note that id argument is optional because the contract will use the caller's address anyway. Once a DID is registered, the provided DID document hash and URI would be stored in the contract along the unique DID string.