Skip to content
Permalink
Browse files

fix: check if identity is revoked before creating the signer

  • Loading branch information...
satazor committed Jun 19, 2019
1 parent 5fa4432 commit 9851ce73bb49a57801b2027c44dbf7352de7fc02
Showing with 14 additions and 3 deletions.
  1. +6 −1 src/identities/identity/index.js
  2. +2 −2 src/sessions/index.js
  3. +6 −0 src/utils/errors/identity/index.js
@@ -2,9 +2,10 @@ import pReduce from 'p-reduce';
import signal from 'pico-signals';
import { createSigner } from 'idm-signatures';
import { formatDid } from '../../utils/did';
import { hashSha256 } from '../../utils/crypto';
import { IdentityRevokedError } from '../../utils/errors';
import { getDescriptorKey, DESCRIPTOR_KEY_PREFIX } from './utils/storage-keys';
import { getOrbitDb, dropOrbitDb, stopOrbitDbReplication } from './utils/orbitdb';
import { hashSha256 } from '../../utils/crypto';
import * as devicesFns from './devices';
import * as backupFns from './backup';
import * as profileFns from './profile';
@@ -75,6 +76,10 @@ class Identity {
}

getSigner() {
if (this.isRevoked()) {
throw new IdentityRevokedError(`Unable to create signer for revoked identity: ${this.getIdentityId()}`);
}

if (!this.#signer) {
this.#signer = this.#createSigner();
}
@@ -1,6 +1,6 @@
import signal from 'pico-signals';
import { assertApp } from '../identities';
import { UnknownSessionError, CreateSessionRevokedIdentityError } from '../utils/errors';
import { UnknownSessionError, IdentityRevokedError } from '../utils/errors';
import { loadSessions, createSession, removeSession, assertSessionOptions } from './session';

class Sessions {
@@ -43,7 +43,7 @@ class Sessions {
const identity = this.#identities.get(identityId);

if (identity.isRevoked()) {
throw new CreateSessionRevokedIdentityError(identityId);
throw new IdentityRevokedError(`Unable to create session for revoked identity: ${identityId}`);
}

const session = this.#getSessionByIdentityAndAppId(identityId, app.id);
@@ -5,6 +5,12 @@ export * from './devices';
export * from './backup';
export * from './apps';

export class IdentityRevokedError extends BaseError {
constructor(message) {
super(message, 'IDENTITY_REVOKED');
}
}

export class InvalidIdentityPropertyError extends BaseError {
constructor(property, value) {
super(`Invalid identity ${property}: ${value}`, 'INVALID_IDENTITY_PROPERTY');

0 comments on commit 9851ce7

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