src/coins/compress.js
function compressKey(key) {
  let out;

  switch (key[0]) {
    case 0x02:
    case 0x03:
      // Key is already compressed.
      out = key;
      break;
    case 0x04:
      // Compress the key normally.
      out = secp256k1.publicKeyConvert(key, true);
      // Store the oddness.
      // Pseudo-hybrid format.
      out[0] = 0x04 | (key[64] & 0x01);
      break;
    default:
      throw new Error('Bad point format.');
  }

  assert(out.length === 33);

  return out;
}
function compressKey(key) {
  let out;

  switch (key[0]) {
    case 0x02:
    case 0x03:
      // Key is already compressed.
      out = key;
      break;
    case 0x04:
      // Compress the key normally.
      out = secp256k1.publicKeyConvert(key, true);
      // Store the oddness.
      // Pseudo-hybrid format.
      out[0] = 0x04 | (key[64] & 0x01);
      break;
    default:
      throw new Error('Bad point format.');
  }

  assert(out.length === 33);

  return out;
}
function compressKey ( key ) { let out ; switch ( key [ 0 ] ) { case 0x02 : case 0x03 : // Key is already compressed. out = key ; break ; case 0x04 : // Compress the key normally. out = secp256k1 . publicKeyConvert ( key , true ) ; // Store the oddness. // Pseudo-hybrid format. out [ 0 ] = 0x04 | ( key [ 64 ] & 0x01 ) ; break ; default : throw new Error ( 'Bad point format.' ) ; } assert ( out . length === 33 ) ; return out ; }
Compress a public key to coins compression format.
@param {Buffer} key
@returns {Buffer}
Compress a public key to coins compression format .