This is an automated email from the ASF dual-hosted git repository.

cmorris pushed a commit to branch BeneficiaryFix
in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git

commit 688cc153125f5bde419b7b4c3d6552e918016a55
Author: Christopher Morris <[email protected]>
AuthorDate: Wed Sep 4 06:56:34 2019 +0100

    Add Beneficiary fix for Bitcoin Wallet
---
 pkg/bitcoinplugin/helpers.go |  8 ++++----
 pkg/defaultservice/order.go  | 18 ++++++++++++++++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/pkg/bitcoinplugin/helpers.go b/pkg/bitcoinplugin/helpers.go
index c7b5e20..eb65167 100644
--- a/pkg/bitcoinplugin/helpers.go
+++ b/pkg/bitcoinplugin/helpers.go
@@ -53,10 +53,10 @@ func deriveFinalPrivateKey(s *Service, order 
documents.OrderDoc, beneficiariesSi
 
        //we are using the beneficiary specified in the order part 1
        privateKeyPart2of2 := order.OrderDocument.OrderPart4.Secret
-       if order.OrderDocument.BeneficiaryCID != nodeID {
-               //need to forward this data to the beneficiary to complete 
redemption
-               return "", errors.New("Currently beneficiary must be the same 
as the Principal")
-       }
+       // if order.OrderDocument.BeneficiaryCID != nodeID {
+       //      //need to forward this data to the beneficiary to complete 
redemption
+       //      return "", errors.New("Currently beneficiary must be the same 
as the Principal")
+       // }
        //restore the Seed
        _, _, ecAddPrivateKey, err := 
cryptowallet.Bip44Address(beneficiariesSeed, cryptowallet.CoinTypeBitcoinMain, 
0, 0, 0)
        if err != nil {
diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go
index d712618..4326ba0 100644
--- a/pkg/defaultservice/order.go
+++ b/pkg/defaultservice/order.go
@@ -208,7 +208,7 @@ func (s *Service) OrderSecret(req *api.OrderSecretRequest) 
(*api.OrderSecretResp
                return nil, err
        }
 
-       _, seed, blsSK, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, 
nodeID)
+       _, _, blsSK, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, 
nodeID)
        if err != nil {
                return nil, err
        }
@@ -219,6 +219,20 @@ func (s *Service) OrderSecret(req *api.OrderSecretRequest) 
(*api.OrderSecretResp
                return nil, errors.Wrap(err, "Fail to retrieve Order from IPFS")
        }
 
+       var beneficiariesSikeSK []byte
+       var beneficiaryCID string
+
+       if req.BeneficiaryIDDocumentCID != "" {
+               beneficiaryCID = req.BeneficiaryIDDocumentCID
+       } else {
+               beneficiaryCID = order.BeneficiaryCID
+       }
+
+       _, beneficiariesSeed, _, beneficiariesSikeSK, err := 
common.RetrieveIdentitySecrets(s.Store, beneficiaryCID)
+       if err != nil {
+               return nil, err
+       }
+
        if err := s.Plugin.ValidateOrderSecretRequest(req, *order); err != nil {
                return nil, err
        }
@@ -253,7 +267,7 @@ func (s *Service) OrderSecret(req *api.OrderSecretRequest) 
(*api.OrderSecretResp
                return nil, err
        }
 
-       finalPrivateKey, finalPublicKey, ext, err := 
s.Plugin.ProduceFinalSecret(seed, sikeSK, order, orderPart4, req, response)
+       finalPrivateKey, finalPublicKey, ext, err := 
s.Plugin.ProduceFinalSecret(beneficiariesSeed, beneficiariesSikeSK, order, 
orderPart4, req, response)
        if err != nil {
                return nil, err
        }

Reply via email to