introduce transaction domain tag
@@ -74,17 +74,22 @@ type Transaction struct {
// PayloadSignatures is a list of signatures generated by the proposer and authorizer roles.
//
- // A payload signature is generated over the inner portion of the transaction (payload).
+ // A payload signature is generated over the inner portion of the transaction (TransactionDomainTag + npayload).
//
// You can find more information about transaction signatures here: https://docs.onflow.org/concepts/transaction-signing/#anatomy-of-a-transaction
PayloadSignatures []TransactionSignature
// EnvelopeSignatures is a list of signatures generated by the payer role.
//
- // A payload signature is generated over the outer portion of the transaction (payload + payloadSignatures).
+ // A envelope signature is generated over the outer portion of the transaction (TransactionDomainTag + payload + payloadSignatures).
//
// You can find more information about transaction signatures here: https://docs.onflow.org/concepts/transaction-signing/#anatomy-of-a-transaction
EnvelopeSignatures []TransactionSignature
+
+ // TransactionDomainTag is prepended to the transaction message before it is signed.
+ //
+ // You can find more information about transaction domain tag here: https://docs.onflow.org/concepts/transaction-signing/#anatomy-of-a-transaction
+ TransactionDomainTag []byte
}
type payloadCanonicalForm struct {
@@ -112,7 +117,9 @@ type transactionCanonicalForm struct {
// NewTransaction initializes and returns an empty transaction.
func NewTransaction() *Transaction {
- return &Transaction{}
+ return &Transaction{
+ TransactionDomainTag: TransactionDomainTag[:],
+ }
}
// ID returns the canonical SHA3-256 hash of this transaction.
@@ -286,7 +293,9 @@ func (t *Transaction) refreshSignerIndex() {
//
// This function returns an error if the signature cannot be generated.
func (t *Transaction) SignPayload(address Address, keyIndex int, signer crypto.Signer) error {
- sig, err := signer.Sign(t.PayloadMessage())
+ message := t.PayloadMessage()
+ message = append(t.TransactionDomainTag, message...)
+ sig, err := signer.Sign(message)
if err != nil {
// TODO: wrap error
return err
@@ -304,7 +313,9 @@ func (t *Transaction) SignPayload(address Address, keyIndex int, signer crypto.S
//
// This function returns an error if the signature cannot be generated.
func (t *Transaction) SignEnvelope(address Address, keyIndex int, signer crypto.Signer) error {
- sig, err := signer.Sign(t.EnvelopeMessage())
+ message := t.EnvelopeMessage()
+ message = append(t.TransactionDomainTag, message...)
+ sig, err := signer.Sign(message)
if err != nil {
// TODO: wrap error
return err
