Skip to content

Commit

Permalink
Add from_secp256k1_pubkey to Value class
Browse files Browse the repository at this point in the history
  • Loading branch information
kallewoof committed Jul 12, 2018
1 parent 2eb1f20 commit 4c5e534
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ void Value::do_combine_pubkeys() {
secp256k1_ec_pubkey_serialize(secp256k1_context_sign, data.data(), &publen, &result, SECP256K1_EC_COMPRESSED);
}

Value Value::from_secp256k1_pubkey(const void* secp256k1_pubkey_ptr) {
if (!secp256k1_context_sign) ECC_Start();

size_t clen = CPubKey::PUBLIC_KEY_SIZE;
CPubKey result;
secp256k1_ec_pubkey_serialize(secp256k1_context_sign, (unsigned char*)result.begin(), &clen, (const secp256k1_pubkey *)secp256k1_pubkey_ptr, SECP256K1_EC_COMPRESSED);
assert(result.size() == clen);
assert(result.IsValid());
return Value(std::vector<uint8_t>(result.begin(), result.end()));
}

#ifdef ENABLE_DANGEROUS

void Value::do_combine_privkeys() {
Expand Down
2 changes: 2 additions & 0 deletions value.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ struct Value {
return HexStr(s);
}

static Value from_secp256k1_pubkey(const void* secp256k1_pubkey_ptr);

explicit Value(const int64_t i) { int64 = i; type = T_INT; }
explicit Value(const opcodetype o) { opcode = o; type = T_OPCODE; }
explicit Value(const std::vector<uint8_t>& d) { data = d; type = T_DATA; }
Expand Down

0 comments on commit 4c5e534

Please sign in to comment.