Skip to content
Permalink
Browse files

fix: remove identity without changing did document if revoked

  • Loading branch information...
paulobmarcos committed Jun 6, 2019
1 parent 17bc3ae commit a1e06a4b075b6770f26739201bafe55c3c574a73
Showing with 15 additions and 12 deletions.
  1. +1 −1 src/identities/identity/devices.js
  2. +3 −3 src/identities/identity/index.js
  3. +11 −8 src/identities/index.js
@@ -224,7 +224,7 @@ export const restoreDevices = async (identityDescriptor, didm, storage, orbitdb)
return new Devices(currentDeviceDescriptor, identityDescriptor, didm, orbitdbStore);
};

export const removeDevices = async (identityDescriptor, didm, storage, orbitdb) => {
export const removeDevices = async (identityDescriptor, storage, orbitdb) => {
await storage.remove(getCurrentDeviceKey(identityDescriptor.id));
await dropStore(orbitdb, ORBITDB_STORE_NAME, ORBITDB_STORE_TYPE);
};
@@ -111,13 +111,13 @@ export const createIdentity = async ({ did, currentDevice, backupData, profileDe

return new Identity(descriptor, storage, orbitdb, devices, backup, profile);
} catch (err) {
await removeIdentity(id, storage, didm, orbitdb);
await removeIdentity(id, storage, orbitdb);

throw new UnableCreateIdentityError(err.message, err.code);
}
};

export const removeIdentity = async (id, storage, didm, ipfs) => {
export const removeIdentity = async (id, storage, ipfs) => {
const descriptorKey = getDescriptorKey(id);
const descriptor = await storage.get(descriptorKey);

@@ -131,7 +131,7 @@ export const removeIdentity = async (id, storage, didm, ipfs) => {
replicate: false,
});

await devicesFns.removeDevices(descriptor, didm, storage, orbitdb);
await devicesFns.removeDevices(descriptor, storage, orbitdb);
await profileFns.removeProfile(descriptor, ipfs, orbitdb);
await backupFns.removeBackup(descriptor, storage);

@@ -140,7 +140,7 @@ class Identities {
currentDevice,
}, this.#storage, this.#didm, this.#ipfs);

this.#identitiesMap[identity.id] = identity;
this.#identitiesMap[identity.getId()] = identity;
this.#updateIdentitiesList();

return identity;
@@ -150,16 +150,19 @@ class Identities {
await this.load();

const identity = this.get(id);
const did = identity.getDid();
const didMethod = parseDid(did).method;

this.#assertDidmSupport(didMethod, 'update');
if (!identity.isRevoked()) {
const did = identity.getDid();
const didMethod = parseDid(did).method;

await this.#didm.update(did, params, (document) => {
document.revokePublicKey(identity.devices.getCurrent().id);
});
this.#assertDidmSupport(didMethod, 'update');

await this.#didm.update(did, params, (document) => {
document.revokePublicKey(identity.devices.getCurrent().id);
});
}

await identityFns.removeIdentity(id, this.#storage, this.#didm, this.#ipfs);
await identityFns.removeIdentity(id, this.#storage, this.#ipfs);

delete this.#identitiesMap[id];
this.#updateIdentitiesList();

0 comments on commit a1e06a4

Please sign in to comment.
You can’t perform that action at this time.