walletrpc: add test sign/verify methods
Test the introduced methods sign/verify messages for single addresses
This commit is contained in:
3 files changed
+153
No files matched your search
@@ -501,4 +501,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
||||
Name: "custom message",
|
||||
TestFunc: testCustomMessage,
|
||||
},
|
||||
{
|
||||
Name: "sign verify message with addr",
|
||||
TestFunc: testSignVerifyMessageWithAddr,
|
||||
},
|
||||
}
|
||||
@@ -1073,3 +1073,120 @@ func assertChannelConstraintsEqual(ht *lntemp.HarnessTest,
|
||||
require.Equal(ht, want.MaxAcceptedHtlcs, got.MaxAcceptedHtlcs,
|
||||
"MaxAcceptedHtlcs mismatched")
|
||||
}
|
||||
|
||||
// testSignVerifyMessageWithAddr tests signing and also verifying a signature
|
||||
// on a message with a provided address.
|
||||
func testSignVerifyMessageWithAddr(ht *lntemp.HarnessTest) {
|
||||
// Using different nodes to sign the message and verify the signature.
|
||||
alice, bob := ht.Alice, ht.Bob
|
||||
|
||||
// Test an lnd wallet created P2WKH address.
|
||||
respAddr := alice.RPC.NewAddress(&lnrpc.NewAddressRequest{
|
||||
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
|
||||
})
|
||||
|
||||
aliceMsg := []byte("alice msg")
|
||||
|
||||
respSig := alice.RPC.SignMessageWithAddr(
|
||||
&walletrpc.SignMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
respValid := bob.RPC.VerifyMessageWithAddr(
|
||||
&walletrpc.VerifyMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Signature: respSig.Signature,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
require.True(ht, respValid.Valid, "alice's signature didn't validate")
|
||||
|
||||
// Test an lnd wallet created NP2WKH address.
|
||||
respAddr = alice.RPC.NewAddress(&lnrpc.NewAddressRequest{
|
||||
Type: lnrpc.AddressType_NESTED_PUBKEY_HASH,
|
||||
})
|
||||
|
||||
respSig = alice.RPC.SignMessageWithAddr(
|
||||
&walletrpc.SignMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
respValid = bob.RPC.VerifyMessageWithAddr(
|
||||
&walletrpc.VerifyMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Signature: respSig.Signature,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
require.True(ht, respValid.Valid, "alice's signature didn't validate")
|
||||
|
||||
// Test an lnd wallet created P2TR address.
|
||||
respAddr = alice.RPC.NewAddress(&lnrpc.NewAddressRequest{
|
||||
Type: lnrpc.AddressType_TAPROOT_PUBKEY,
|
||||
})
|
||||
|
||||
respSig = alice.RPC.SignMessageWithAddr(
|
||||
&walletrpc.SignMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
respValid = bob.RPC.VerifyMessageWithAddr(
|
||||
&walletrpc.VerifyMessageWithAddrRequest{
|
||||
Msg: aliceMsg,
|
||||
Signature: respSig.Signature,
|
||||
Addr: respAddr.Address,
|
||||
},
|
||||
)
|
||||
|
||||
require.True(ht, respValid.Valid, "alice's signature didn't validate")
|
||||
|
||||
// Test verifying a signature with an external P2PKH address.
|
||||
// P2PKH address type is not supported by the lnd wallet therefore
|
||||
// using an external source (bitcoin-core) for address and
|
||||
// signature creation.
|
||||
externalMsg := []byte("external msg")
|
||||
externalAddr := "msS5c4VihSiJ64QzvMMEmWh6rYBnuWo2xH"
|
||||
|
||||
// Base64 encoded signature created with bitcoin-core regtest.
|
||||
externalSig := "H5DqqM7Cc8xZnYBr7j3gD4XD+AuQsim9Un/IxBrrhBA7I9//" +
|
||||
"3exuQRg+u7HpwG65yobPsew6RMUteyuxyNkLF5E="
|
||||
|
||||
respValid = alice.RPC.VerifyMessageWithAddr(
|
||||
&walletrpc.VerifyMessageWithAddrRequest{
|
||||
Msg: externalMsg,
|
||||
Signature: externalSig,
|
||||
Addr: externalAddr,
|
||||
},
|
||||
)
|
||||
|
||||
require.True(ht, respValid.Valid, "external signature didn't validate")
|
||||
|
||||
// Test verifying a signature with a different address which
|
||||
// initially was used to create the following signature.
|
||||
// externalAddr is a valid legacy P2PKH bitcoin address created
|
||||
// with bitcoin-core.
|
||||
externalAddr = "mugbg8CqFe9CbdrYjFTkMhmL3JxuEXkNbY"
|
||||
|
||||
// Base64 encoded signature created with bitcoin-core regtest but with
|
||||
// the address msS5c4VihSiJ64QzvMMEmWh6rYBnuWo2xH.
|
||||
externalSig = "H5DqqM7Cc8xZnYBr7j3gD4XD+AuQsim9Un/IxBrrhBA7I9//" +
|
||||
"3exuQRg+u7HpwG65yobPsew6RMUteyuxyNkLF5E="
|
||||
|
||||
respValid = alice.RPC.VerifyMessageWithAddr(
|
||||
&walletrpc.VerifyMessageWithAddrRequest{
|
||||
Msg: externalMsg,
|
||||
Signature: externalSig,
|
||||
Addr: externalAddr,
|
||||
},
|
||||
)
|
||||
|
||||
require.False(ht, respValid.Valid, "external signature did validate")
|
||||
}
|
||||
Reference in new issue
Block a user