# All files / src/utils getAddress.js

100% Statements 5/5
100% Branches 2/2
100% Functions 1/1
100% Lines 5/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    1013x

    13x
    36x

    36x
    36x

     const utils = require('ethereumjs-util');

    module.exports = function getAddress(pubkey) {
      const bytes = pubkey.startsWith('0x')
        ? Buffer.from(pubkey.replace('0x', ''), 'hex')
        : Buffer.from(pubkey, 'base64');
      const hash = utils.sha256(bytes).slice(0, 20);
      return hash.toString('base64');
    };