This section mainly introduces the method of generating and modifying the multi-signed customized DID document, which isn't available in the ordinary document.
The multi-signature (m:n) rule requires n>1. M represents the number of signers, that is, the number of signatures in the proof of document. If the number of signatures is less than m, it means that the document at this time is not really a valid multi-signed document, and the remaining controllers who haven’t signed need to sign the documents.
Example
let rootPath ="root/store";let store =awaitDIDStore.open(rootPath);let storePass ="pwd";............let rootidentity =store.loadRootidentity();//get the first controllerlet controller1 =awaitidentity.newDid(storePass);awaitcontroller1.publish(storePass);//get the second controllerlet controller2 =awaitidentity.newDid(storePass);awaitcontroller2.publish(storePass);//get the third controllerlet controller3 =awaitidentity.newDid(storePass);awaitcontroller3.publish(storePass);............let did =newDID("did:elastos:byeworld");//new multi-signed Customized DID//customized document has three controller and multisig is 2:3, so document must be signed by two controllers. controller2 is the first signer.let doc =awaitcontroller2.newCustomizedDidWithController(did, [controller1.getSubject(),controller2.getSubject(),controller3.getSubject()],2, storePass);//check signer is enoughif (!doc.isQualified())//the second signer, and finished multi-signure.awaitcontroller1.signWithDocument(doc, storePass);//check the docif (doc.isQualified()) {console.log("create multi-signed customized document successfully." ); } else {console.log("create multi-signed customized document failed." );}............//modify the document:remove controller1,mutisig 2:2let db =DIDDocument.Builder.newFromDocument(doc).edit(controller2);db.removeController(controller1.getSubject());//do other things............let doc =db.seal();awaitcontroller3.signWithDocument(doc, storePass);if (doc.isValid()) {console.log("create multi-signed customized document successfully." ); } else {console.log("create multi-signed customized document failed." );}doc.setEffectiveController(controller3.getSubject());awaitdoc.publish(storePass);............store.close();
Usage
The methods of adding and removing elements in the ordinary DID document are also applicable to the customized DID document, and what is described here is the unique content of customized DID document.
This method generates the initial multi-signed document. At this time, only one controller signs the primary data in the obtained document, and whether the number of signatures accords with the multi-signature rule is verified by the isQualified method.
public isQualified(): boolean;
This method tells whether the number of signatures in the current customized document lives up to the multi-signature rule. If false is returned, the controller who hasn’t signed will continue to complete the signature work to improve the document.
public async addController( controller: DID| string): Promise<Builder>;
public removeController( controller: DID| string): Builder;
The above two methods are apparently exclusive to the customized DID document. If adding and removing controllers is used for the ordinary DID document, an error is returned.
public setMultiSignature( m: number): Builder;
This method resets the over-signature rule.
public setEffectiveController(controller: DID):void;
Before signing the multi-signed customized DID document, the effective controller should set to specify which controller’s master key is used for signing.