tests/lib.js
/**
 * JWKS is just an array of keys. We need to find the last private key that
 * also has a corresponding public key. The pair is recognized by having the
 * same "kid" property.
 * @param {Array} keys JWKS.keys 
 */
JWKS is just an array of keys. We need to find the last private key that
also has a corresponding public key. The pair is recognized by having the
same "kid" property.
JWKS is just an array of keys . We need to find the last private key that also has a corresponding public key . The pair is recognized by having the same " kid " property .
function findKeyPair(keys) {
    let out = null;
    keys.forEach(key => {
        if (!key.kid) return;
        if (!Array.isArray(key.key_ops)) return;
        if (key.key_ops.indexOf("sign") == -1) return;
        const publicKey = keys.find(k => {
            return (
                k.kid === key.kid &&
                k.alg === key.alg &&
                Array.isArray(k.key_ops) &&
                k.key_ops.indexOf("verify") > -1
            );
        })
        if (publicKey) {
            out = { privateKey: key, publicKey };
        }
    });
    return out;
}
function findKeyPair ( keys ) { let out = null ; keys . forEach ( key => { if ( ! key . kid ) return ; if ( ! Array . isArray ( key . key_ops ) ) return ; if ( key . key_ops . indexOf ( "sign" ) == - 1 ) return ; const publicKey = keys . find ( k => { return ( k . kid === key . kid && k . alg === key . alg && Array . isArray ( k . key_ops ) && k . key_ops . indexOf ( "verify" ) > - 1 ) ; } ) if ( publicKey ) { out = { privateKey : key , publicKey } ; } } ) ; return out ; }
JWKS is just an array of keys.
JWKS is just an array of keys .