All files / src/chain key-type.ts

95.23% Statements 20/21
85.71% Branches 12/14
100% Functions 4/4
95% Lines 19/20

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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  1x 1x 1x 1x     1x 1x 94x   70x   17x   6x   1x     1x   94x 80x   14x   93x   70x   17x   6x            
/** Supported Antelope/EOSIO curve types. */
export enum KeyType {
    K1 = 'K1',
    R1 = 'R1',
    WA = 'WA',
}
 
export namespace KeyType {
    export function indexFor(value: KeyType) {
        switch (value) {
            case KeyType.K1:
                return 0
            case KeyType.R1:
                return 1
            case KeyType.WA:
                return 2
            default:
                throw new Error(`Unknown curve type: ${value}`)
        }
    }
    export function from(value: number | string) {
        let index: number
        if (typeof value !== 'number') {
            index = KeyType.indexFor(value as KeyType)
        } else {
            index = value
        }
        switch (index) {
            case 0:
                return KeyType.K1
            case 1:
                return KeyType.R1
            case 2:
                return KeyType.WA
            default:
                throw new Error('Unknown curve type')
        }
    }
}