Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove service + remove public key #144

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/daf-ethr-did/src/identity-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ export class IdentityController extends AbstractIdentityController {
}
}

async removeService(service: { id: string; type: string; serviceEndpoint: string }): Promise<any> {
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<any> {
const serializedIdentity = await this.identityStore.get(this.did)
const ethrDid = new EthrDID({ address: this.address, provider: this.web3Provider })
Expand All @@ -75,4 +92,26 @@ export class IdentityController extends AbstractIdentityController {
return false
}
}

async removePublicKey(keyId: string): Promise<any> {
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.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)
return false
}
}
}