All files / src/crypto curves.ts

88.88% Statements 8/9
83.33% Branches 5/6
100% Functions 1/1
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22    1x             27x 27x 2x 1x 1x 1x         27x    
import {ec} from 'elliptic'
 
const curves: {[type: string]: ec} = {}
 
/**
 * Get curve for key type.
 * @internal
 */
export function getCurve(type: string): ec {
    let rv = curves[type]
    if (!rv) {
        if (type === 'K1') {
            rv = curves[type] = new ec('secp256k1')
        } else Eif (type === 'R1') {
            rv = curves[type] = new ec('p256')
        } else {
            throw new Error(`Unknown curve type: ${type}`)
        }
    }
    return rv
}