0

I would like to understand why is it not possible to verify a subkey signature with the polkadotJs keyring.

When it is signed with the keyring everything is good:

    const msg = "message to be verified"
    const keyring_signature = alice.sign(msg)
    console.log("isvalid keyring: ", alice.verify(msg, keyring_signature)) // true
    console.log(u8aToHex(alice.publicKey)) // 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d


However, when I try to sign it subkey, with the same Alice account, the verification returns false:

subkey inspect //Alice                                                                                   
Secret Key URI `//Alice` is account:
  Secret seed:      0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a
  Public key (hex): 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
  Account ID:       0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
  SS58 Address:     5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY


echo "message to be verified" | subkey sign 0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a  
// this returned a 64bytes signature
    const msg = "message to be verified"
    const subkey_signature = "96c02390e077231595c4805aecdd242bbdd43456d289c6050ad819d42275032836eb5ea4a48a2aa2b1150219904b7de2b08f5b1a63e3ad8459c29d0e7dd00e8e"
    console.log("isvalid subkey : ", alice.verify(msg, subkey_signature)) // false

Can anyone help? thanks!

1 Answers1

1

echo adds a newline character unless you remove it with the -n flag. Try:

echo -n "message to be verified" | subkey sign ...

That signature should verify correctly with Polkadot JS.

joepetrowski
  • 165
  • 2
  • 10
  • Thanks for your answer, unfortunately I am still running into trouble. I tried several options. `echo -e "message to be verified" ` and `echo $'message to be verified"` both do not print newline character but they still cannot be verified on PolkadotJs keyring. – whalelephant Feb 05 '20 at 02:54