I'd like to know if there's a way to sign a message? Any help would be appreciated. Thanks!
3 Answers
All that ledger knows how to do is to offer signatures of different kinds of messages the client app sends it. So in that sense your question refers more to capability of the Tezos client you are connecting your Ledger to (full node, tezbox etc...).
At the moment unfortunately the option is not offered in either client to sign regular string messages (similarly to say in the bitcoin standard gui wallet) so the answer to your question is "no". The closest thing that is available is with the full node to sign bytes messages with the command
./tezos-client sign bytes <data> for <src>
which would request a signature from your ledger is that one controls src
That being said it is a useful feature to have and worth requesting to various wallet developpers!
-
1Warning:
sign bytes
can sign transfers, etc. One must be careful what the<data>
is.– TomJan 7, 2020 at 0:47
There are no very convenient tezos-client commands or RPCs to help with this yet, but one can currently sign a Micheline expression in a conventional way like this:
$ tezos-client hash data '"hello, world"' of type string | grep 'Raw packed data:' | cut -d: -f2
0x05010000000c68656c6c6f2c20776f726c64
$ tezos-client unpack michelson data 0x05010000000c68656c6c6f2c20776f726c64
"hello, world"
$ tezos-client sign bytes 0x05010000000c68656c6c6f2c20776f726c64 for key
...
Such a signature will be accepted, for example, by a contract doing {PUSH string "hello, world"; PACK; BLAKE2B; PUSH signature ...; PUSH key ...; CHECK_SIGNATURE; ASSERT}
.
This convention is used for example by the genesis multisig vesting contracts.
As of today the Ledger wallet app will not confirm such a signature, displaying "Sign Unverified". Maybe someday it will display the hash displayed by hash data
.
I don't feel comfortable describing this without providing a warning:
It can be dangerous to sign Micheline expressions.
Note also that sign bytes
is dangerous. It is crucial above that the bytes being signed start with 0x05
, which conventionally indicates that a Micheline expression follows. If the bytes start with 0x01
-0x04
, they might mean something else! (If they start with 0x03
, for example, they might mean a transfer!)
Generally, always take care which messages you sign with which keys.
Remember that your signatures are valid forever, so future situations are relevant too.
See also two relevant Michelson anti-patterns, which start to hint at related complexity here (from the contract author's perspective): Signatures alone do not prevent replay attacks, Do not assume users will use a unique key for every smart contract.
WARNING: The following hack is dangerous because it treats your message as an operation which could be reinterpreted in a later context to mean something you did not intend.
You can actually convince the ledger to sign arbitrary things right now. It will display a "Sign Unverified?" prompt:
tezos-client sign bytes 0x03$(echo "hi there!" | xxd -ps | tr -d '\n') for <account>
But having a fully supported solution to this where the ledger actually shows you the message (or some verifiable version of it) would be ideal.
-
2Warning: do not sign arbitrary things using 0x03. 0x03 signifies that an operation follows.– TomJan 7, 2020 at 0:47
-
I'm glad you point this out. This hack should be considered risky as those signatures could end up being reinterpreted in a later context as having meaning that you didn't intend. Tezos will hopefully support real arbitrary messages at some point. Mar 12, 2020 at 18:36
-