64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
|
|
/** Base class for all Shade errors */
|
||
|
|
export class ShadeError extends Error {
|
||
|
|
constructor(message: string) {
|
||
|
|
super(message);
|
||
|
|
this.name = 'ShadeError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Signature verification failed (e.g. invalid signed prekey) */
|
||
|
|
export class InvalidSignatureError extends ShadeError {
|
||
|
|
constructor(message = 'Signature verification failed') {
|
||
|
|
super(message);
|
||
|
|
this.name = 'InvalidSignatureError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** AES-GCM decryption failed (wrong key, tampered ciphertext, or bad nonce) */
|
||
|
|
export class DecryptionError extends ShadeError {
|
||
|
|
constructor(message = 'Decryption failed') {
|
||
|
|
super(message);
|
||
|
|
this.name = 'DecryptionError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** No session exists for the given address */
|
||
|
|
export class NoSessionError extends ShadeError {
|
||
|
|
constructor(address: string) {
|
||
|
|
super(`No session for address: ${address}`);
|
||
|
|
this.name = 'NoSessionError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Too many skipped messages in a chain (possible DoS or sync issue) */
|
||
|
|
export class MaxSkipExceededError extends ShadeError {
|
||
|
|
constructor(requested: number, max: number) {
|
||
|
|
super(`Cannot skip ${requested} messages (max: ${max})`);
|
||
|
|
this.name = 'MaxSkipExceededError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Duplicate message detected (message key already consumed) */
|
||
|
|
export class DuplicateMessageError extends ShadeError {
|
||
|
|
constructor() {
|
||
|
|
super('Duplicate message: key already consumed');
|
||
|
|
this.name = 'DuplicateMessageError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Remote identity key has changed unexpectedly */
|
||
|
|
export class UntrustedIdentityError extends ShadeError {
|
||
|
|
constructor(address: string) {
|
||
|
|
super(`Untrusted identity key for: ${address}`);
|
||
|
|
this.name = 'UntrustedIdentityError';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Required prekey not found in storage */
|
||
|
|
export class PreKeyNotFoundError extends ShadeError {
|
||
|
|
constructor(keyId: number, type: 'signed' | 'one-time') {
|
||
|
|
super(`${type} prekey not found: ${keyId}`);
|
||
|
|
this.name = 'PreKeyNotFoundError';
|
||
|
|
}
|
||
|
|
}
|