2022-11-01 11:22:00 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.gammaspectra.live/P2Pool/p2pool-observer/types"
|
|
|
|
)
|
|
|
|
|
2022-11-07 22:59:52 +00:00
|
|
|
var TxProofV2DomainSeparatorHash = Keccak256([]byte("TXPROOF_V2")) // HASH_KEY_TXPROOF_V2
|
2022-11-05 05:29:12 +00:00
|
|
|
func GenerateTxProofV2(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
|
2022-11-01 11:22:00 +00:00
|
|
|
comm := &SignatureComm_2{}
|
|
|
|
comm.Message = prefixHash
|
|
|
|
|
|
|
|
//shared secret
|
2022-11-05 05:29:12 +00:00
|
|
|
comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
|
|
|
comm.Separator = TxProofV2DomainSeparatorHash
|
2022-11-05 05:29:12 +00:00
|
|
|
comm.TransactionPublicKey = txKey.PublicKey()
|
2022-11-01 11:22:00 +00:00
|
|
|
comm.RecipientViewPublicKey = recipientViewPublicKey
|
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
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
|
|
|
|
}
|
2022-11-01 11:22:00 +00:00
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
return comm.Bytes()
|
|
|
|
}, txKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
|
|
|
return comm.KeyDerivation, signature
|
|
|
|
}
|
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
func GenerateTxProofV1(prefixHash types.Hash, txKey PrivateKey, recipientViewPublicKey PublicKey, recipientSpendPublicKey PublicKey) (derivation PublicKey, signature *Signature) {
|
2022-11-01 11:22:00 +00:00
|
|
|
comm := &SignatureComm_2_V1{}
|
|
|
|
comm.Message = prefixHash
|
|
|
|
|
|
|
|
//shared secret
|
2022-11-05 05:29:12 +00:00
|
|
|
comm.KeyDerivation = txKey.GetDerivation(recipientViewPublicKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
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)
|
|
|
|
}
|
2022-11-01 11:22:00 +00:00
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
comm.RandomDerivation = k.GetDerivation(recipientViewPublicKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
2022-11-05 05:29:12 +00:00
|
|
|
return comm.Bytes()
|
|
|
|
}, txKey)
|
2022-11-01 11:22:00 +00:00
|
|
|
|
|
|
|
return comm.KeyDerivation, signature
|
|
|
|
}
|