Fork of github.com/did-method-plc/did-method-plc
1export class PlcError extends Error { 2 plcError = true 3 constructor(msg: string) { 4 super(msg) 5 } 6 7 static is(obj: unknown): obj is PlcError { 8 if (obj && typeof obj === 'object' && obj['plcError'] === true) { 9 return true 10 } 11 return false 12 } 13} 14export class ImproperOperationError extends PlcError { 15 constructor(public reason: string, public op: unknown) { 16 super(`Improperly formatted operation, ${reason}: ${op}`) 17 } 18} 19 20export class MisorderedOperationError extends PlcError { 21 constructor() { 22 super('Operations not correctly ordered') 23 } 24} 25 26export class LateRecoveryError extends PlcError { 27 constructor(public timeLapsed: number) { 28 super( 29 `Recovery operation occurred outside of the allowed 72 hr recovery window. Time lapsed: ${timeLapsed}`, 30 ) 31 } 32} 33 34export class GenesisHashError extends PlcError { 35 constructor(public expected: string) { 36 super( 37 `Hash of genesis operation does not match DID identifier: ${expected}`, 38 ) 39 } 40} 41 42export class InvalidSignatureError extends PlcError { 43 constructor(public op: unknown) { 44 super(`Invalid signature on op: ${JSON.stringify(op)}`) 45 } 46} 47 48export class UnsupportedKeyError extends PlcError { 49 constructor(public key: string, public err: unknown) { 50 super(`Unsupported key type ${key}: ${err}`) 51 } 52} 53 54export class ImproperlyFormattedDidError extends PlcError { 55 constructor(public reason: string) { 56 super(`Improperly formatted did: ${reason}`) 57 } 58}