bool CScriptCompressor::IsToPubKey(CPubKey &pubkey) const {
    if (script.size() == 35 && script[0] == 33 && script[34] == OP_CHECKSIG &&
        (script[1] == 0x02 || script[1] == 0x03)) {
        pubkey.Set(&script[1], &script[34]);
        return true;
    }
    if (script.size() == 67 && script[0] == 65 && script[66] == OP_CHECKSIG &&
        script[1] == 0x04) {
        pubkey.Set(&script[1], &script[66]);
        // if not fully valid, a case that would not be compressible
        return pubkey.IsFullyValid();
    }
    return false;
}
Exemplo n.º 2
0
void CECKey::GetPubKey(CPubKey &pubkey, bool fCompressed) {
    EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED);
    int nSize = i2o_ECPublicKey(pkey, NULL);
    assert(nSize);
    assert(nSize <= 65);
    unsigned char c[65];
    unsigned char *pbegin = c;
    int nSize2 = i2o_ECPublicKey(pkey, &pbegin);
    assert(nSize == nSize2);
    pubkey.Set(&c[0], &c[nSize]);
}