import {Adsa, ECDSA} from '../types'; import {HashCtor} from '@tios/hash'; export function extend(esa: ECDSA): ECDSA { // @ts-ignore esa.algo = 'ECDSA'; esa.adsa = (hash: HashCtor): Adsa => new ECDSAAdsa(esa, hash); return esa; } class ECDSAAdsa implements Adsa { readonly id: string; constructor(public asym: ECDSA, protected hash: HashCtor) { this.id = asym.id + '_' + hash.id; } sign(msg: string | Buffer, key: any): Buffer { msg = Buffer.isBuffer(msg) ? msg : Buffer.from(msg); return this.asym.sign(this.hash.digest(msg), key); } verify(msg: string | Buffer, sig: Buffer, key: any): boolean { msg = Buffer.isBuffer(msg) ? msg : Buffer.from(msg); return this.asym.verify(this.hash.digest(msg), sig, key); } }