From c59ff92d35b75de3f113c46787a327d8131ce96c Mon Sep 17 00:00:00 2001 From: Niko Lockenvitz Date: Tue, 12 May 2020 11:47:58 +0200 Subject: [PATCH 1/2] feat: remove service + remove public key --- .../daf-ethr-did/src/identity-controller.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/daf-ethr-did/src/identity-controller.ts b/packages/daf-ethr-did/src/identity-controller.ts index 562bae876..75c30ea84 100644 --- a/packages/daf-ethr-did/src/identity-controller.ts +++ b/packages/daf-ethr-did/src/identity-controller.ts @@ -51,6 +51,23 @@ export class IdentityController extends AbstractIdentityController { } } + async removeService(service: { id: string; type: string; serviceEndpoint: string }): Promise { + const ethrDid = new EthrDID({ address: this.address, provider: this.web3Provider }) + + const attribute = 'did/svc/' + service.type + const value = service.serviceEndpoint + const { gas } = this + debug('ethrDid.revokeAttribute', { attribute, value, gas }) + try { + const txHash = await ethrDid.revokeAttribute(attribute, value, gas) + debug({ txHash }) + return txHash + } catch (e) { + debug(e.message) + return false + } + } + async addPublicKey(type: 'Ed25519' | 'Secp256k1', proofPurpose?: string[]): Promise { const serializedIdentity = await this.identityStore.get(this.did) const ethrDid = new EthrDID({ address: this.address, provider: this.web3Provider }) @@ -75,4 +92,26 @@ export class IdentityController extends AbstractIdentityController { return false } } + + async removePublicKey(keyId: string): Promise { + const serializedIdentity = await this.identityStore.get(this.did) + const serializedKey = serializedIdentity.keys.find(item => item.kid === keyId) + if (!serializedKey) throw Error('Key not found') + const key = this.kms.getKey(serializedKey.kid) + + const usg = 'veriKey' + const attribute = 'did/pub/' + key.type + '/' + usg + '/hex' + const value = '0x' + key.publicKeyHex + const { gas } = this + + debug('ethrDid.revokeAttribute', { attribute, value, gas }) + try { + const txHash = await ethrDid.revokeAttribute(attribute, value, gas) + debug({ txHash }) + return txHash + } catch (e) { + debug(e.message) + return false + } + } } From 5cd0bffee5074f24e420dcc799f172159a9dec66 Mon Sep 17 00:00:00 2001 From: Niko Lockenvitz Date: Wed, 19 Aug 2020 17:21:49 +0200 Subject: [PATCH 2/2] fix: fix bug in removePublicKey --- packages/daf-ethr-did/src/identity-controller.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/daf-ethr-did/src/identity-controller.ts b/packages/daf-ethr-did/src/identity-controller.ts index 75c30ea84..a11d74103 100644 --- a/packages/daf-ethr-did/src/identity-controller.ts +++ b/packages/daf-ethr-did/src/identity-controller.ts @@ -94,20 +94,20 @@ export class IdentityController extends AbstractIdentityController { } async removePublicKey(keyId: string): Promise { - const serializedIdentity = await this.identityStore.get(this.did) - const serializedKey = serializedIdentity.keys.find(item => item.kid === keyId) - if (!serializedKey) throw Error('Key not found') - const key = this.kms.getKey(serializedKey.kid) + const ethrDid = new EthrDID({ address: this.address, provider: this.web3Provider }) + + const key = await this.kms.getKey(keyId) const usg = 'veriKey' - const attribute = 'did/pub/' + key.type + '/' + usg + '/hex' - const value = '0x' + key.publicKeyHex + const attribute = 'did/pub/' + key.serialized.type + '/' + usg + '/hex' + const value = '0x' + key.serialized.publicKeyHex const { gas } = this debug('ethrDid.revokeAttribute', { attribute, value, gas }) try { const txHash = await ethrDid.revokeAttribute(attribute, value, gas) debug({ txHash }) + this.kms.deleteKey(key.serialized.kid); return txHash } catch (e) { debug(e.message)