Skip to content

Commit

Permalink
refactoring(spv-790) hmac calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
augustync committed May 24, 2024
1 parent c3b67e7 commit 69aedba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions engine/types/type42/linking_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func calculateHMAC(pubSharedSecret []byte, reference string) ([]byte, error) {
if reference == "" {
return nil, errors.New("invalid invoice number")
}
h := hmac.New(sha256.New, []byte(reference))
if _, err := h.Write(pubSharedSecret); err != nil {
h := hmac.New(sha256.New, pubSharedSecret)
if _, err := h.Write([]byte(reference)); err != nil {
return nil, fmt.Errorf("error writing HMAC message - %w", err)
}
return h.Sum(nil), nil
Expand Down
4 changes: 2 additions & 2 deletions engine/types/type42/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func sha256Hash(data string) []byte {

// Helper function to compute the expected HMAC
func computeExpectedHMAC(pubSharedSecret []byte, reference string, idx int) []byte {
h := hmac.New(sha256.New, []byte(fmt.Sprintf("%s-%d", reference, idx)))
h.Write(pubSharedSecret)
h := hmac.New(sha256.New, pubSharedSecret)
h.Write([]byte(fmt.Sprintf("%s-%d", reference, idx)))
return h.Sum(nil)
}

0 comments on commit 69aedba

Please # to comment.