git.gammaspectra.live/P2Pool/consensus/v3@v3.8.0/monero/crypto/proofs.go (about)

     1  package crypto
     2  
     3  import (
     4  	"git.gammaspectra.live/P2Pool/consensus/v3/types"
     5  )
     6  
     7  var TxProofV2DomainSeparatorHash = Keccak256([]byte("TXPROOF_V2")) // HASH_KEY_TXPROOF_V2
     8  func GenerateTxProofV2(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
     9  	comm := &SignatureComm_2{}
    10  	comm.Message = prefixHash
    11  
    12  	//shared secret
    13  	comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
    14  
    15  	comm.Separator = TxProofV2DomainSeparatorHash
    16  	comm.TransactionPublicKey = txKey.PublicKey()
    17  	comm.RecipientViewPublicKey = recipientViewPublicKey
    18  
    19  	signature = CreateSignature(func(k PrivateKey) []byte {
    20  		if recipientSpendPublicKey == nil {
    21  			// compute RandomPublicKey = k*G
    22  			comm.RandomPublicKey = k.PublicKey()
    23  			comm.RecipientSpendPublicKey = nil
    24  		} else {
    25  			// compute RandomPublicKey = k*B
    26  			comm.RandomPublicKey = k.GetDerivation(recipientSpendPublicKey)
    27  			comm.RecipientSpendPublicKey = recipientSpendPublicKey
    28  		}
    29  
    30  		comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
    31  
    32  		return comm.Bytes()
    33  	}, txKey)
    34  
    35  	return comm.KeyDerivation, signature
    36  }
    37  
    38  func GenerateTxProofV1(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
    39  	comm := &SignatureComm_2_V1{}
    40  	comm.Message = prefixHash
    41  
    42  	//shared secret
    43  	comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
    44  
    45  	signature = CreateSignature(func(k PrivateKey) []byte {
    46  		if recipientSpendPublicKey == nil {
    47  			// compute RandomPublicKey = k*G
    48  			comm.RandomPublicKey = k.PublicKey()
    49  		} else {
    50  			// compute RandomPublicKey = k*B
    51  			comm.RandomPublicKey = k.GetDerivation(recipientSpendPublicKey)
    52  		}
    53  
    54  		comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
    55  
    56  		return comm.Bytes()
    57  	}, txKey)
    58  
    59  	return comm.KeyDerivation, signature
    60  }