Skip to content

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo committed Aug 29, 2022
1 parent 3a27263 commit 3c04379
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions sign/ln/ln_signer.go
Original file line number Diff line number Diff line change
@@ -34,12 +34,12 @@ func (self *LNSigner) SignMsg(msg *string) (*string, error) {
func (self *LNSigner) VerifyMsg(key *string, signature *string, msg *string) (bool, error) {
u8sing, err := self.encoder.DecodeString(*signature)
if err != nil {
return false, nil
return false, err
}

// https://github.com/ElementsProject/lightning/blob/master/lightningd/signmessage.c#L177
if len(u8sing) != 65 {
return false, goutils.Errf("zbase is too is wrong size %d, need to be exactly 65", len(u8sing))
return false, goutils.Errf("zbase with wrong size %d, need to be exactly 65", len(u8sing))
}

// The signature is over the double-sha256 hash of the message.
@@ -52,5 +52,5 @@ func (self *LNSigner) VerifyMsg(key *string, signature *string, msg *string) (bo
return false, nil
}
pubKeyHex := hex.EncodeToString(pubKey.SerializeCompressed())
return pubKeyHex == *key, goutils.NotImplementYet()
return pubKeyHex == *key, nil
}
6 changes: 4 additions & 2 deletions sign/ln/ln_signer_test.go
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ func TestLNSignerVerifyMsgTrue(t *testing.T) {
zbase32 := "d7m5xma1tia1hw6mjkeixqoocexiyoyn1jgm53mncszdeut5j9r1k1nq7wsrh3pkk3c3xp7mkuuxmbneitu3us36cqfn9a6sdu3wa45j"
msg := "Testing go utils"
signer := NewLNSigner()
verified, _ := signer.VerifyMsg(&pubKey, &zbase32, &msg)
verified, err := signer.VerifyMsg(&pubKey, &zbase32, &msg)
assert.Nil(t, err)
assert.Equal(t, true, verified, "Return level returned it is diffirent")
}

@@ -25,6 +26,7 @@ func TestLNSignerVerifyMsgFalse(t *testing.T) {
zbase32 := "d7m5xma1tia1hw6mjkeixqoocexiyoyn1jgm53mncszdeut5j9r1k1nq7wsrh3pkk3c3xp7mkuuxmbneitu3us36cqfn9a6sdu3wa45j"
msg := "Invalid message"
signer := NewLNSigner()
verified, _ := signer.VerifyMsg(&pubKey, &zbase32, &msg)
verified, err := signer.VerifyMsg(&pubKey, &zbase32, &msg)
assert.Nil(t, err)
assert.Equal(t, false, verified, "Return level returned it is diffirent")
}

0 comments on commit 3c04379

Please sign in to comment.