Derive compressed public key
198003
def compressed(self):
        
        order = ecdsa.SECP256k1.generator.order()
        p = ecdsa.VerifyingKey.from_string(
            compat_bytes(self), curve=ecdsa.SECP256k1).pubkey.point
        x_str = ecdsa.util.number_to_string(p.x(), order)
        # y_str = ecdsa.util.number_to_string(p.y(), order)
        compressed = hexlify(
            compat_bytes(chr(2 + (p.y() & 1)), 'ascii') + x_str).decode(
            'ascii')
        return (compressed)
1367722
def _convert_public_key(ecdsa_curve_name, result):
    """"""
    if ecdsa_curve_name == 'nist256p1':
        if (result[64] & 1) != 0:
            result = bytearray([0x03]) + result[1:33]
        else:
            result = bytearray([0x02]) + result[1:33]
    else:
        result = result[1:]
        keyX = bytearray(result[0:32])
        keyY = bytearray(result[32:][::-1])
        if (keyX[31] & 1) != 0:
            keyY[31] |= 0x80
        result = b'\x00' + bytes(keyY)
    return bytes(result)
907622
def get_uncompressed_private_and_public_keys( privkey_str ):
    
    if not isinstance(privkey_str, (str, unicode)):
        raise ValueError("private key given is not a string")

    pk = ecdsa_private_key(str(privkey_str))
    pk_hex = pk.to_hex()

    # force uncompressed
    if len(pk_hex) > 64:
        if pk_hex[-2:] != '01':
            raise ValueError("private key does not end in '01'")

        pk_hex = pk_hex[:64]

    pubk_hex = ecdsa_private_key(pk_hex).public_key().to_hex()
    return pk_hex, pubk_hex
795639
function deriveKeypair(parent_secret, child_name, signature_scheme) {
  if (!signature_scheme) {
    signature_scheme = 'ec_secp256k1';
  }

  var pair = {};

  if (signature_scheme === 'ec_secp256k1') {

    pair.private = deriveSecret(parent_secret, child_name, 'sha256');

    // If the private key is greater than the curve modulus we
    // use a counter to get a new random secret
    var modulus = new BigInteger(ecurve.getCurveByName('secp256k1').n, 16);
    var counter = 1;
    while (!pair.private || modulus.compareTo(pair.private) < 0) {
      pair.private = deriveSecret(parent_secret, child_name + '_' + counter, 'sha256');
      counter += 1;
    }

    pair.public = new bitcoinjs.ECKey(new BigInteger(pair.private, 16), false).pub.toHex();

  } else {

    throw new Error('Signature scheme: ' + signature_scheme + ' not currently supported');

  }

  return pair;
}
1287679
function getPubKeyFromPriKey(priKeyBytes) {
  var ec = new EC('secp256k1');
  var key = ec.keyFromPrivate(priKeyBytes, 'bytes');
  var pubkey = key.getPublic();
  var x = pubkey.x;
  var y = pubkey.y;
  var xHex = x.toString('hex');
  while (xHex.length < 64) {
    xHex = "0" + xHex;
  }
  var yHex = y.toString('hex');
  while (yHex.length < 64) {
    yHex = "0" + yHex;
  }
  var pubkeyHex = "04" + xHex + yHex;
  var pubkeyBytes = hexStr2byteArray(pubkeyHex);
  return pubkeyBytes;
}
1172365
def sec_to_public_pair(sec, generator=None, strict=True):
    """"""
    byte_count = (generator.p().bit_length() + 7) >> 3 if generator else (len(sec) - 1)
    x = from_bytes_32(sec[1:1 + byte_count])
    sec0 = sec[:1]
    if len(sec) == 1 + byte_count * 2:
        isok = sec0 == b'\4'
        if not strict:
            isok = isok or (sec0 in [b'\6', b'\7'])
        if isok:
            y = from_bytes_32(sec[1+byte_count:1+2*byte_count])
            return (x, y)
    elif len(sec) == 1 + byte_count:
        if not strict or (sec0 in (b'\2', b'\3')):
            is_y_odd = (sec0 != b'\2')
            return generator.points_for_x(x)[is_y_odd]
    raise EncodingError("bad sec encoding for public key")
776308
def key_bytes(self):
        
        return self.key.public_bytes(
            encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo
        )
1156263
def get_public_key(self):
        """"""
        return PublicKey.from_verifying_key(
            self._private_key.get_verifying_key(),
            network=self.network, compressed=self.compressed)
270311
def pubkey(self, identity, ecdh=False):
        """"""
        with self.device:
            pubkey = self.device.pubkey(ecdh=ecdh, identity=identity)
        return formats.decompress_pubkey(
            pubkey=pubkey, curve_name=identity.curve_name)
850969
function generateKeyPair() {
    const plain = nacl.sign.keyPair();
    const num = nacl.randomBytes(8);

    const publicKey = new Uint8Array(2 + 8 + 32);
    const secretKey = new Uint8Array(2 + 2 + 4 + 16 + 8 + 8 + 64);

    publicKey[0] = secretKey[0] = 69; // 'E'
    publicKey[1] = secretKey[1] = 100; // 'd'

    secretKey[2] = 66; // 'B'
    secretKey[3] = 75; // 'K'

    publicKey.set(num, 2);
    secretKey.set(num, 32);

    publicKey.set(plain.publicKey, 10);
    secretKey.set(plain.secretKey, 40);

    const checksum = nacl.hash(plain.secretKey).subarray(0, 8);
    secretKey.set(checksum, 24)

    return {
        publicKey: Buffer.from(publicKey.buffer).toString('base64'),
        secretKey: Buffer.from(secretKey.buffer).toString('base64')
    };
}
1166948
def _tls_compress(alg, p):
    
    c = TLSCompressed()
    c.type = p.type
    c.version = p.version
    c.data = alg.compress(p.data)
    c.len = len(c.data)
    return c
523721
public static ECKey fromPrivate(BigInteger privKey, boolean compressed) {
        ECPoint point = publicPointFromPrivate(privKey);
        return new ECKey(privKey, getPointWithCompression(point, compressed));
    }
1351349
def _key_digest(self, secret_key):
        
        '''
            
        '''
        
        from hashlib import md5, sha256
        from base64 import b64encode
        key_bytes = sha256(secret_key.encode('utf-8')).digest()
        key_b64 = b64encode(key_bytes).decode()
        digest_bytes = md5(key_bytes).digest()
        digest_b64 = b64encode(digest_bytes).decode()
        
        return key_b64, digest_b64
453706
function getPubkeyHex(privkey_hex) {
   let privkey = BigInteger.fromBuffer( decodePrivateKey(privkey_hex) );
   let public_key = new bitcoinjs.ECPair(privkey);

   public_key.compressed = false;
   let public_key_str = public_key.getPublicKeyBuffer().toString('hex');
   return public_key_str;
}
1033780
def to_point
      p = pubkey
      p ||= generate_pubkey(priv_key, compressed: compressed)
      ECDSA::Format::PointOctetString.decode(p.htb, Bitcoin::Secp256k1::GROUP)
    end
12183
def decompress_pubkey(pubkey, curve_name):
    
    vk = None
    if len(pubkey) == 33:
        decompress = {
            CURVE_NIST256: _decompress_nist256,
            CURVE_ED25519: _decompress_ed25519,
            ECDH_CURVE25519: _decompress_ed25519,
        }[curve_name]
        vk = decompress(pubkey)

    if not vk:
        msg = 'invalid {!s} public key: {!r}'.format(curve_name, pubkey)
        raise ValueError(msg)

    return vk
896681
function deriveSecret(parent_secret, child_name, hash_algorithm) {
  if (!hash_algorithm) {
    hash_algorithm = 'sha512';
  }

  return crypto.createHmac(hash_algorithm, parent_secret).update(child_name).digest('hex');
}