MCPcopy Create free account
hub / github.com/ElementsProject/elements / ComputeAndAddToScalarOffset

Function ComputeAndAddToScalarOffset

src/blindpsbt.cpp:350–375  ·  view source on GitHub ↗

Computes a scalar offset and adds it to another existing one

Source from the content-addressed store, hash-verified

348
349// Computes a scalar offset and adds it to another existing one
350bool ComputeAndAddToScalarOffset(uint256& a, CAmount value, const uint256& asset_blinder, const uint256& value_blinder)
351{
352 // If both asset and value blinders are null, 0 is added to the offset, so nothing actually happens
353 if (asset_blinder.IsNull() && value_blinder.IsNull()) return true;
354
355 uint256 scalar;
356 if (!CalculateScalarOffset(scalar, value, asset_blinder, value_blinder)) return false;
357
358 // When we start out, the result (a) is 0, so just set it to the scalar we just computed.
359 if (a.IsNull()) {
360 a = scalar;
361 } else {
362 uint256 scalar_negated = scalar;
363 if (secp256k1_ec_seckey_negate(secp256k1_blind_context, scalar_negated.begin()) != 1) {
364 return false;
365 }
366 // Special-case zero, which would otherwise cause `secp256k1_ec_seckey_tweak_add` to fail
367 if (scalar_negated == a) {
368 a = uint256{};
369 } else {
370 // If we have a, then add the scalar to it.
371 if (secp256k1_ec_seckey_tweak_add(secp256k1_blind_context, a.begin(), scalar.begin()) != 1) return false;
372 }
373 }
374 return true;
375}
376
377BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::map<uint32_t, std::tuple<CAmount, CAsset, uint256, uint256>> our_input_data, std::map<uint32_t, std::pair<CKey, CKey>> our_issuances_to_blind)
378{

Callers 1

BlindPSBTFunction · 0.85

Calls 5

CalculateScalarOffsetFunction · 0.85
IsNullMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected