github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/host/negotiate.go (about) 1 package host 2 3 import ( 4 "github.com/NebulousLabs/Sia/crypto" 5 "github.com/NebulousLabs/Sia/modules" 6 "github.com/NebulousLabs/Sia/types" 7 ) 8 9 // createRevisionSignature creates a signature for a file contract revision 10 // that signs on the file contract revision. The renter should have already 11 // provided the signature. createRevisionSignature will check to make sure that 12 // the renter's signature is valid. 13 func createRevisionSignature(fcr types.FileContractRevision, renterSig types.TransactionSignature, secretKey crypto.SecretKey, blockHeight types.BlockHeight) (types.Transaction, error) { 14 hostSig := types.TransactionSignature{ 15 ParentID: crypto.Hash(fcr.ParentID), 16 PublicKeyIndex: 1, 17 CoveredFields: types.CoveredFields{ 18 FileContractRevisions: []uint64{0}, 19 }, 20 } 21 txn := types.Transaction{ 22 FileContractRevisions: []types.FileContractRevision{fcr}, 23 TransactionSignatures: []types.TransactionSignature{renterSig, hostSig}, 24 } 25 sigHash := txn.SigHash(1) 26 encodedSig, err := crypto.SignHash(sigHash, secretKey) 27 if err != nil { 28 return types.Transaction{}, err 29 } 30 txn.TransactionSignatures[1].Signature = encodedSig[:] 31 err = modules.VerifyFileContractRevisionTransactionSignatures(fcr, txn.TransactionSignatures, blockHeight) 32 if err != nil { 33 return types.Transaction{}, err 34 } 35 return txn, nil 36 }