bool PaymentCode::Sign( const uint32_t nym, const Credential& credential, proto::Signature& sig, const OTPasswordData* pPWData) const { if (!pubkey_) { otErr << __FUNCTION__ << ": Payment code not instantiated.\n"; return false; } serializedAsymmetricKey privatekey = App::Me().Crypto().BIP32().GetPaymentCode(nym); if (!privatekey) { otErr << __FUNCTION__ << ": Failed to derive private key for" << " payment code.\n"; return false; } OTData existingKeyData, compareKeyData; serializedAsymmetricKey compareKey = App::Me().Crypto().BIP32().PrivateToPublic(*privatekey); compareKey->clear_path(); std::dynamic_pointer_cast<AsymmetricKeySecp256k1> (pubkey_)->GetKey(existingKeyData); compareKeyData.Assign(compareKey->key().c_str(), compareKey->key().size()); if (!(existingKeyData == compareKeyData)) { otErr << __FUNCTION__ << ": Private key is not valid for this" << " payment code.\n"; return false; } std::unique_ptr<OTAsymmetricKey> signingKey(OTAsymmetricKey::KeyFactory(*privatekey)); serializedCredential serialized = credential.asSerialized( Credential::AS_PUBLIC, Credential::WITHOUT_SIGNATURES); bool goodSig = signingKey->Sign( proto::ProtoAsData<proto::Credential>(*serialized), sig, pPWData, nullptr, ID(), proto::SIGROLE_NYMIDSOURCE); return goodSig; }
bool MasterCredential::Verify(const Credential& credential) const { serializedCredential serializedCred = credential.asSerialized( Credential::AS_PUBLIC, Credential::WITHOUT_SIGNATURES); if (!proto::Check<proto::Credential>( *serializedCred, 0, 0xFFFFFFFF, credential.Role(), false)) { otErr << __FUNCTION__ << ": Invalid credential syntax.\n"; return false; } bool sameMaster = (id_ == credential.MasterID()); if (!sameMaster) { otErr << __FUNCTION__ << ": Credential does not designate this" << " credential as its master.\n"; return false; } SerializedSignature masterSig = credential.MasterSignature(); if (!masterSig) { otErr << __FUNCTION__ << ": Missing master signature.\n"; return false; } if (!m_SigningKey) { otErr << __FUNCTION__ << ": Master is missing signing keypair.\n"; return false; } return m_SigningKey->Verify( proto::ProtoAsData<proto::Credential>(*serializedCred), *masterSig); }