Skip to content

Commit

Permalink
error comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Smirnov committed Mar 18, 2019
1 parent 44d82b4 commit c986599
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
15 changes: 5 additions & 10 deletions src/EThree.ts
Expand Up @@ -31,7 +31,8 @@ import { withDefaults } from './utils/object';

export interface IEThreeInitOptions {
/**
* Implementation of IKeyEntryStorage. If not specified using IndexedDB Key Storage from [Virgil SDK](https://github.com/virgilsecurity/virgil-sdk-javascript);
* Implementation of IKeyEntryStorage. If not specified using IndexedDB Key Storage from
* [Virgil SDK](https://github.com/virgilsecurity/virgil-sdk-javascript);
*/
keyEntryStorage?: IKeyEntryStorage;
/**
Expand Down Expand Up @@ -165,7 +166,6 @@ export default class EThree {
} finally {
this[_inProcess] = false;
}
return;
}

/**
Expand Down Expand Up @@ -224,9 +224,7 @@ export default class EThree {
}

/**
* Encrypts data.
* @param message - Plain data you want to encrypt.
* @param publicKey - Public keys of recipients. If omitted encrypts only for yourself.
* Encrypts data for recipient(s) public key(s). If recipient is you - omit public key parameter.
*/
async encrypt(
message: ArrayBuffer,
Expand Down Expand Up @@ -257,9 +255,7 @@ export default class EThree {
}

/**
* Decrypts data.
* @param message - Encrypted data you want to decrypt.
* @param publicKey - Public key of sender. If sender is you - omit that parameter.
* Decrypts data and verify signature of sender by his public key. If sender is you - omit public key parameter.
*/
async decrypt(message: string, publicKey?: VirgilPublicKey): Promise<string>;
async decrypt(message: Buffer, publicKey?: VirgilPublicKey): Promise<Buffer>;
Expand All @@ -278,9 +274,8 @@ export default class EThree {

/**
* Find public keys for user identities which registered on Virgil Cloud.
* @param identities;
*/
async lookupPublicKeys(identities: string): Promise<VirgilPublicKey>;
async lookupPublicKeys(identity: string): Promise<VirgilPublicKey>;
async lookupPublicKeys(identities: string[]): Promise<LookupResult>;
async lookupPublicKeys(identities: string[] | string): Promise<LookupResult | VirgilPublicKey> {
const argument = isArray(identities) ? identities : [identities];
Expand Down
2 changes: 1 addition & 1 deletion src/PrivateKeyLoader.ts
Expand Up @@ -59,7 +59,7 @@ export default class PrivateKeyLoader {
}

async resetLocalPrivateKey() {
await this.localStorage.remove(this.identity).catch(this.handleResetError);
await this.localStorage.remove(this.identity);
}

async resetPrivateKeyBackup(password: string) {
Expand Down
33 changes: 32 additions & 1 deletion src/errors.ts
@@ -1,5 +1,8 @@
export const DUPLICATE_IDENTITIES = 'Identities in array should be unique';

/**
* Custom error class for errors specific to Virgil E3kit.
*/
export class SdkError extends Error {
name: string;
constructor(m: string, name: string = 'SdkError') {
Expand All @@ -9,6 +12,9 @@ export class SdkError extends Error {
}
}

/**
* Error thrown by {@link EThree.register}.
*/
export class IdentityAlreadyExistsError extends SdkError {
constructor() {
super(
Expand All @@ -18,24 +24,37 @@ export class IdentityAlreadyExistsError extends SdkError {
}
}

/**
* Error thrown by {@link EThree.encrypt}, {@link EThree.decrypt} and{@link EThree.backupPrivateKey}
*/
export class RegisterRequiredError extends SdkError {
constructor() {
super('This identity is not registered', 'RegisterRequiredError');
}
}

/**
* Error thrown by {@link EThree.backupPrivateKey}, {@link EThree.changePassword} and
* {@link EThree.resetPrivateKeyBackup}
*/
export class WrongKeyknoxPasswordError extends SdkError {
constructor() {
super('Password from remote private key storage is invalid', 'WrongKeyknoxPasswordError');
}
}

/**
* Error thrown by {@link EThree.lookupPublicKeys}
*/
export class EmptyArrayError extends SdkError {
constructor(method: string) {
super(`Array must be non empty in ${method} method`);
}
}

/**
* Error thrown by {@link EThree.rotatePrivateKey} and {@link EThree.restorePrivateKey}
*/
export class PrivateKeyAlreadyExistsError extends SdkError {
constructor() {
super(
Expand All @@ -45,12 +64,18 @@ export class PrivateKeyAlreadyExistsError extends SdkError {
}
}

/**
* Error thrown by {@link EThree.resetPrivateKeyBackup}.
*/
export class PrivateKeyNoBackupError extends SdkError {
constructor() {
super("Backup copy of private key doesn't exist", 'PrivateKeyNoBackupError');
}
}

/**
* Error thrown by {@link EThree.register}, {@link EThree.rotatePrivateKey} and {@link EThree.lookupPublicKeys}.
*/
export class MultipleCardsError extends SdkError {
constructor(public identity: string) {
super(
Expand All @@ -66,15 +91,21 @@ export type LookupResultWithErrors = {
| Error;
};

/**
* Error thrown by {@link EThree.lookupPublicKeys}.
*/
export class LookupError extends SdkError {
constructor(public lookupResult: LookupResultWithErrors) {
super(
`Failed some public keys lookups. You can see the results by calling error.lookupResult property of this error instance`,
'Failed some public keys lookups. You can see the results by calling error.lookupResult property of this error instance',
'LookupError',
);
}
}

/**
* Error thrown by {@link EThree.lookupPublicKeys}.
*/
export class LookupNotFoundError extends SdkError {
constructor(public identity: string) {
super(`${identity} not found`, 'LookupNotFoundError');
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Expand Up @@ -32,7 +32,6 @@
"excludeExternals": true,
"suppressExcessPropertyErrors": true,
"suppressImplicitAnyIndexErrors": true,
"theme": "markdown",
"hideGenerator": true,
"readme": "none"
}
Expand Down

0 comments on commit c986599

Please sign in to comment.