@@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77package ttx
88
99import (
10+ "bytes"
1011 "context"
1112 "time"
1213
@@ -15,6 +16,7 @@ import (
1516 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/sig"
1617 "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
1718 "github.com/hyperledger-labs/fabric-token-sdk/token"
19+ "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/multisig"
1820 "github.com/hyperledger-labs/fabric-token-sdk/token/services/tokens"
1921 "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
2022 jsession "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/json/session"
@@ -68,7 +70,7 @@ func (s *EndorseView) Call(context view.Context) (interface{}, error) {
6870 return nil , errors .Wrapf (err , "failed acknowledging transaction" )
6971 }
7072
71- // cache the token request into the tokens db
73+ // cache the token request into the tokens db, should we use the received token request?
7274 t , err := tokens .GetService (context , s .tx .TMSID ())
7375 if err != nil {
7476 return nil , errors .Wrapf (err , "failed to get tokens db for [%s]" , s .tx .TMSID ())
@@ -145,21 +147,28 @@ func (s *EndorseView) handleSignatureRequests(context view.Context) error {
145147 return nil
146148}
147149
150+ // receiveTransaction is used to intercept the last round of transaction distribution from CollectEndorsementsView.
151+ // Indeed, after having collected the auditor signatures, if needed, and the approval,
152+ // CollectEndorsementsView distributes the token request with the additional signatures.
148153func (s * EndorseView ) receiveTransaction (context view.Context ) (* Transaction , error ) {
149- logger .DebugfContext (context .Context (), "Receive transaction with envelope..." )
150- // TODO: this might also happen multiple times because of the pseudonym. Avoid this by identity resolution at the sender
154+ logger .DebugfContext (context .Context (), "receive transaction..." )
151155 tx , err := ReceiveTransaction (context )
152156 if err != nil {
153157 return nil , errors .Wrapf (err , "failed receiving transaction" )
154158 }
155159
156- // TODO: compare with the existing transaction
157- logger .DebugfContext (context .Context (), "Processes Fabric Envelope with ID [%s]" , tx .ID ())
158-
159- // Set the envelope
160- request := s .tx .TokenRequest
161- s .tx = tx
162- s .tx .TokenRequest = request
160+ // check that the content of the token request match
161+ m1 , err := s .tx .TokenRequest .MarshalToSign ()
162+ if err != nil {
163+ return nil , errors .Wrap (err , "failed to marshal token request to sign from the local transaction" )
164+ }
165+ m2 , err := tx .TokenRequest .MarshalToSign ()
166+ if err != nil {
167+ return nil , errors .Wrap (err , "failed to marshal token request to sign from the remote transaction" )
168+ }
169+ if ! bytes .Equal (m1 , m2 ) {
170+ return nil , errors .Errorf ("token request's signer does not match the expected signer" )
171+ }
163172 return tx , nil
164173}
165174
@@ -191,20 +200,33 @@ func (s *EndorseView) ack(context view.Context, receivedTx *Transaction) error {
191200 return nil
192201}
193202
203+ // requiredSigners extracts from the given token request a list of identities that can generate a signature over it.
194204func requiredSigners (ctx context.Context , request * token.Request ) ([]token.Identity , error ) {
195205 issuerSigners := request .IssueSigners ()
196206 transferSigners := request .TransferSigners ()
197207 res := make ([]token.Identity , 0 , len (issuerSigners )+ len (transferSigners ))
198208 sigService := request .TokenService .SigService ()
199209 for _ , signer := range issuerSigners {
200- if sigService .IsMe (ctx , signer ) {
201- res = append (res , signer )
210+ multiSigners , _ , _ := multisig .Unwrap (signer )
211+ if len (multiSigners ) != 0 {
212+ res = append (res , multiSigners ... )
213+ continue
202214 }
215+ res = append (res , signer )
203216 }
204217 for _ , signer := range transferSigners {
205- if sigService .IsMe (ctx , signer ) {
206- res = append (res , signer )
218+ multiSigners , _ , _ := multisig .Unwrap (signer )
219+ if len (multiSigners ) != 0 {
220+ res = append (res , multiSigners ... )
221+ continue
222+ }
223+ res = append (res , signer )
224+ }
225+ subset := make ([]token.Identity , 0 , len (res ))
226+ for _ , res := range res {
227+ if sigService .IsMe (ctx , res ) {
228+ subset = append (subset , res )
207229 }
208230 }
209- return res , nil
231+ return subset , nil
210232}
0 commit comments