export enum DID_COMMANDS { CREATE_DID = "createDID", ADD_KEYPAIR = "addKeyPair", ADD_SERVICEPOINT = "addServicePoint" } export interface DIDTx { "version" : string; "command" : DID_COMMANDS; "data" : {}; //Interface? "proof" : {}; //Interface? //TODO add proof } interface publicKey { "id" : string; "type" : string; //TODO Change this into an enum of supported types in this resolver? "owner" : string; "publicKeyPem" : string; //TODO: Generic or support the different public key parameters? } interface authentication { "type" : string; //TODO Change this into an enum of supported types in this resolver? "publicKey" : string; } export interface ServicePoint { "id" : string; "type" : string; "serviceEndpoint" : string } export class DID{ private context : string; private id : string; private authenticationProtocol: authentication[]; private publicKeys : publicKey[]; private servicePoints : ServicePoint[]; constructor(context:string,id:string,authentication:authentication[], publicKey: publicKey[]){ this.context = context; this.id = id; this.authenticationProtocol = authentication; this.publicKeys = publicKey; this.servicePoints = []; } public getContext(){ return this.context; } public getId(){ return this.id; } public addAuthentication(type:string,publicKey:string){ this.authenticationProtocol.push({type,publicKey}); } public removeAuthentication(index: number){ if(index < this.authenticationProtocol.length) delete this.authenticationProtocol[index]; } public getAuthentication(){ return this.authenticationProtocol; } public addPublicKey(id:string,type:string, owner:string,publicKeyPem:string){ this.publicKeys.push({id,type,owner,publicKeyPem}); } public removePublicKey(index: number){ if(index < this.publicKeys.length) delete this.publicKeys[index]; } public getPublicKey(){ return this.publicKeys; } public getJson() { return JSON.stringify({ "@context":this.context, "id":this.id, "publicKey": this.publicKeys, "authentication": this.authenticationProtocol, "service" : this.servicePoints }) } public AddServicePoint(servicePoint : ServicePoint ) { this.servicePoints.push(servicePoint); } public getServicePoints() : ServicePoint[] { return this.servicePoints; } }