Skip to content

Latest commit

 

History

History
210 lines (157 loc) · 8.95 KB

ONTID_protocol_spec.md

File metadata and controls

210 lines (157 loc) · 8.95 KB

中文版

ONT ID Identification Protocol and Smart Contract Implementation Specification

Version V0.6.0

“Entity” refers to individuals, legal entities (organizations, enterprises, institutions, etc.), objects (mobile phones, automobiles, IoT devices, etc.), and contents (articles, copyrights, etc.) in the real world, and “identity” refers to the entity's identity within the network. Ontology uses Ontology Identifier (ONT ID) to identify and manage the entities' identities. On Ontology Blockchain, one entity can correspond to multiple individual identities, and there is no relation between multiple identities.

The ONT ID is a decentralized identification protocol and it has the features of decentralization, self-management, privacy protection, security and ease of use. Each ONT ID corresponds to an ONT ID Description Object (DDO).

The ONT ID protocol has been completely implemented by the smart contract of Ontology Blockchain. As a protocol layer, it follows a decoupled design, so it is not limited to Ontology Blockchain, but can also be implemented on other blockchains.

ONT ID Protocol

1.1 ONT ID generation

The ONT ID is a URI that is generated by each entity itself. The generation algorithm needs to guarantee that when two ONTs are simultaneously registering on Ontology, the consensus node can check whether the ID is registered.

ONT ID generation algorithm:

To prevent the user from entering the Ont ID by mistake, we define a valid Ont ID that must contain 4 bytes of verification data. We are going to describe in detail how to generate a valid Ont ID.

  1. Generate a 32-byte temporary random nonce, and calculate h = Hash160 (nonce), data = VER || h;
  2. Calculate a 4-byte verification data, that is, checksum = SHA256(SHA256(data))[0:3];
  3. Make idString = data || checksum;
  4. Cascade "did:ont:" with data, that is, ontId = "did:ont:" || idString;
  5. Output ontId.

The size of "did:ont:" is 8 bytes and the size of “idString” is 25 bytes, so the total size of “ontId” is 33bytes.

1.2 Self-management

Ontology applies digital signature technology to guarantee entities have rights to manage their own identities. The ONT ID is bound to the entity's public key when it registers, thereby indicating its ownership. The use of the ONT ID and the modification of its attributes require the owner's digital signature. The entity can independently determine the scope of use of its ONT ID and set the public key bounded by ONT ID and manage the attributes of the ONT ID.

1.3 Multiple key binding

Ontology supports a variety of domestic and international standardized digital signature algorithms such as RSA, ECDSA, and SM2. The algorithm applied to the key that is bounded by ONT ID should be specified. At the same time, an ONT ID can bound multiple different keys to meet the usage requirements of entities in different application scenarios.

1.4 Recovery of identity loss

The owner of the ONT ID can assign someone else to execute his management rights, such as modifying the attributes of the ONT ID and replacing the key when the key is lost. The assigned person can implement a variety of access control logic such as “AND”, “OR”, and “(m, n)-thresholds”.

1.5 Identity description object DDO specification

The identity description object DDO corresponding to the ONT ID is stored in the Ontology Blockchain. It is written to the blockchain by the controller of the DDO and is open to all users for reading.

The DDO specification contains the following information:

  • PublicKeys:The information of the public key used for identity authentication, including public key id, public key type, and public key data;
  • Attributes:All attributes make up a JSON object;
  • Recovery:The assigned restorer can help reset the user's public key list.

For example,

{
	"OntId": "did:ont:xxxxxxxx",
	"Owners": [
		{
			"PubKeyId": "did:ont:xxxxxxxx#keys-1",
			"Type": "ECDSA",
			"Curve": "nistp256",
			"Value": "02yyyyyyyy"
		}, 
		{
			"PubKeyId": "did:ont:xxxxxxxx#keys-2",
			"Type": "SM2",
			"Curve": "sm2p256",
			"Value": "02zzzzzzzz"
		}
	],
	"Attributes": {
		"SocialCredential": {
			"service": "weibo",
			"username": "alice",
			"proof": "https://weibo.com/status/ttttttt"
		},
		"OfficialCredential": {
			"service": "eID",
			"eId": "dddddddd",
			"proof": "03xz4f....."
		}
	},
	"Recovery": "TA63T1gxXPXWsBqHtBKcV4NhFBhw3rtkAF"
}

Smart Contract Implementation Specification

“IdContract” is a smart contract implementation of the ONT ID protocol on the Ontology Blockchain platform. With the ONT IdContract, users can manage their own public key lists, modify their personal profiles, and add account restorers.

2.1 How to call

The external interface of the IdContract has only one main function. Its parameters include the name of the sub-function (called operation code - op) and the parameter lists – params, which is passed to the sub-function.。

public static Object Main(string op, object[] params);

The return value of most of sub-functions is a boolean type, which represents the success or failure of the execution operation. After correct execution, an event message will be pushed to notify the caller. For the specific message type, please refer to the “API description” subsection.

The call of Ontology smart contract

By sending a transaction with a type of InvocationTransaction, transaction payload will include contract address and parameters. For more detailed information, please refer to Contract Call.

2.2 IdContract Interface Definition

a. Identity registration

When the users registers their identities, they must submit a public key, and this operation must be initiated by this public key.

bool RegIdWIthPublicKey(byte[] ontId, byte[] publicKey); 

Parameters:

  • ontId: User ID, byte[] type;
  • publicKey: Public key, byte[] type.

b. Add a control key

The user adds a new public key to his public key list.

bool AddKey(byte[] ontId, byte[] newPublicKey, byte[] sender); 

Parameters:

  • ontId:User’s ont Id;
  • newPublicKey:The new public key to be added;
  • sender:The initiator of the transaction, the account's existing public key, or the restorer.

c. Delete a control key

Remove a public key from the user's public key list.

bool RemoveKey(byte[] ontId, byte[] oldPublicKey, byte[] sender);

Parameters:

  • ontId:User’s Ont ID;
  • oldPublicKey:The old public key that needs to be deleted;
  • sender:The initiator of the transaction, the account's existing public key, or the restorer.

d. Key recovery mechanism

Add and modify the account restorer.

bool AddRecovery(byte[] ontId, byte[20] recovery, byte[] publicKey);

In the function AddRecovery, recovery can be added if and only if the publicKey is the account's existing public key, and the restorer has not been set.

Parameters:

  • ontId:User’s Ont ID;
  • recovery:Recovery address, that is, script hash ScriptHash;
  • publicKey:User’s public key
bool ChangeRecovery(byte[] ontId, byte[] newRecovery, byte[20] oldRecovery);

This contract call must be initiated by oldRecovery. Parameters:

  • ontId:User’s Ont ID;
  • newRecovery:New restorer
  • oldRecovery:Existing restorer

e. Attribute management

The addition, deletion, and modification of the user’s attributes must be authorized by the user.

bool AddAttribute(byte[] ontId, byte[] path, byte[] type, byte[] value, byte[] publicKey);
  • ontId: User’s Ont ID; path: The path of attribute name;
  • type: Attribute type; value: Attribute value;
  • publicKey: The user's public key.

Must be called by a valid public key, and the publicKey is in the user's public key list. If the attribute does not exist, the attribute will be inserted. Otherwise the original attribute will be updated.

bool AddAttributeArray(byte[] ontId, byte[] tuples, byte[] publicKey);

f. Query identity information

byte[] GetDDO(byte[] ontId);

Return all the user's information, which is a serialization of a JSON object.

byte[] GetPublicKeys(byte[] ontId);

Return all the user's public keys.

g. Event push

IdContract contains three kinds of event messages:

  • Register: Push the messages related to identity registration.

    Field Type Description
    op string message type
    ontId byte[] registered Ont Id
  • PublicKey: Push the messages related to public key operations.

    Field Type Description
    op string message type:"add" or "remove"
    ontId byte[] user's Ont Id
    publicKey byte[] public key data
  • Attribute: Push the messages related to attribute operations.

    Field Type Description
    op string message type:"add"、"update"、"remove"
    ontId byte[] user's Ont Id
    attrName byte[] attribute name