import cose from 'cose-js' ; import { ALGOS } from './types' ; import { SigningKey } from '../../services/api/vaccine-cert' ; import * as errors from './errors' ; async function verifyECDSA ( message , keys ) { for ( const key of keys ) { try { const verifiedBuf = await cose . sign . verify ( message , { key : { kid : key . kid , x : Buffer . from ( key . x , 'base64' ) , y : Buffer . from ( key . y , 'base64' ) } } ) ; if ( verifiedBuf ) { return verifiedBuf ; } } catch ( e ) { console . log ( 'Sig failed' , key . kid , e ) ; } } return errors . invalidSignature ( ) ; } async function verifyRSA ( _message , _keys ) { return errors . invalidSignature ( ) ; } export default async function verifySignature ( message , algo , keys ) { if ( algo === ALGOS . ECDSA_256 ) { return verifyECDSA ( message , keys ) ; } else if ( algo === ALGOS . RSA_PSS_256 ) { return verifyRSA ( message , keys ) ; } else { return errors . unknownSigAlgo ( ) ; } }