consensus/monero/crypto/proofs.go
DataHoarder fe75cf259c
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
P2Pool consensus v3.0.0
Migrate cmd utils, cmds to own repository
2024-04-03 19:43:13 +02:00

61 lines
1.9 KiB
Go

package crypto
import (
"git.gammaspectra.live/P2Pool/consensus/v3/types"
)
var TxProofV2DomainSeparatorHash = Keccak256([]byte("TXPROOF_V2")) // HASH_KEY_TXPROOF_V2
func GenerateTxProofV2(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
comm := &SignatureComm_2{}
comm.Message = prefixHash
//shared secret
comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
comm.Separator = TxProofV2DomainSeparatorHash
comm.TransactionPublicKey = txKey.PublicKey()
comm.RecipientViewPublicKey = recipientViewPublicKey
signature = CreateSignature(func(k PrivateKey) []byte {
if recipientSpendPublicKey == nil {
// compute RandomPublicKey = k*G
comm.RandomPublicKey = k.PublicKey()
comm.RecipientSpendPublicKey = nil
} else {
// compute RandomPublicKey = k*B
comm.RandomPublicKey = k.GetDerivation(recipientSpendPublicKey)
comm.RecipientSpendPublicKey = recipientSpendPublicKey
}
comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
return comm.Bytes()
}, txKey)
return comm.KeyDerivation, signature
}
func GenerateTxProofV1(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
comm := &SignatureComm_2_V1{}
comm.Message = prefixHash
//shared secret
comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
signature = CreateSignature(func(k PrivateKey) []byte {
if recipientSpendPublicKey == nil {
// compute RandomPublicKey = k*G
comm.RandomPublicKey = k.PublicKey()
} else {
// compute RandomPublicKey = k*B
comm.RandomPublicKey = k.GetDerivation(recipientSpendPublicKey)
}
comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
return comm.Bytes()
}, txKey)
return comm.KeyDerivation, signature
}