Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document signatures in FAQ #21

Open
gsmachado opened this issue Aug 7, 2023 · 14 comments
Open

Document signatures in FAQ #21

gsmachado opened this issue Aug 7, 2023 · 14 comments

Comments

@gsmachado
Copy link
Member

No description provided.

@gsmachado gsmachado self-assigned this Aug 7, 2023
@mialbu mialbu self-assigned this Aug 9, 2023
@mialbu
Copy link
Member

mialbu commented Aug 9, 2023

@gsmachado, we should add a question about singing and verifying messages with NeoLine. NeoLine implements some modifications to the message before signing in order to support Ledger (as of now Ledger only supports signing transactions for N3).
This means that all messages signed with NeoLine will undergo these modifications (including those not signing with Ledger).

The steps are shown in the example comment here:

Image

So, if you want to sign the message neow3j is awesome!, the message that will be signed by NeoLine will be:
"010001f0" + "12" + "6e656f77336a20697320617765736f6d6521" + "0000"
= "010001f0126e656f77336a20697320617765736f6d65210000"

6e656f77336a20697320617765736f6d6521* -> hex of neow3j is awesome!
12 = hexadecimal for decimal 18 (# of hex values of the message's hex representation above (*))
010001f0 and 0000 are specific values needed to enable signing with ledger.

@gsmachado
Copy link
Member Author

010001f0 and 0000 are specific values needed to enable signing with ledger.

I understand that 010001f0 (prefix) and 0000 (suffix) are fixed values. But do you know (or can ask) more info on what's exactly that for Ledger?

@mialbu
Copy link
Member

mialbu commented Aug 9, 2023

Asked, will come back to you.

@mialbu
Copy link
Member

mialbu commented Aug 9, 2023

Do you know what exactly the constant values 010001f0 and 0000 stand for? Is this for tricking Ledger into believing this message is a transaction?

Yes

@gsmachado
Copy link
Member Author

it would be good to know WHAT are these hex values... like, transaction type? chain id? what?

@gsmachado
Copy link
Member Author

Or, maybe, is this something specific to the Neo app for Ledger, and not Ledger itself?!

@gsmachado
Copy link
Member Author

just FYI: https://github.com/LedgerHQ/app-neo3

@mialbu
Copy link
Member

mialbu commented Aug 9, 2023

Or, maybe, is this something specific to the Neo app for Ledger, and not Ledger itself?!

I assume this is the case, yes. Can't confirm it though.

@gsmachado
Copy link
Member Author

gsmachado commented Aug 9, 2023

I understand that 010001f0 (prefix) and 0000 (suffix) are fixed values. But do you know (or can ask) more info on what's exactly that for Ledger?

@hacfox maybe can you clarify these questions? ☝️

We'd like to know what 010001f0 (prefix) and 0000 (suffix) are, and where is this required (NeoLine? Ledger? which component is requiring this and for what purpose)

@hacfox
Copy link

hacfox commented Aug 10, 2023

@gsmachado @mialbu Yes
So first of all, The Ledger only supports transaction signing for Neo Legacy and N3.
For Neo Legacy, In order to enable Ledger to sign regular messages, we had to construct the message as a transaction and then have it signed.

Look into this part ➡️ serialize from neon-js
IMAGE 2023-08-10 13:57:42

  1. We construct the message as a IssueTransaction transaction(the transaction type is 0x01)
  2. the serializeExclusive() is "", Why empty here?
  3. 01 -> attributes length, f0 -> usage's hex of 240, concatenatedString -> data
    telegram-cloud-photo-size-5-6244391323624912221-y

@hacfox
Copy link

hacfox commented Aug 10, 2023

Furthermore, using the same approach for signmessage on N3 as on Neo Legacy doesn't make sense. Initially, we wanted to ensure compatibility with N3 Ledger, but the transaction construction has changed, so we didn't proceed and opened an issue here.

@csmuller
Copy link
Member

csmuller commented Aug 10, 2023

@hacfox, So that means that signing a message with NeoLine using Ledger on N3 is not possible at the moment?

AFAIK, transaction signing of N3 transactions is possible with the Neo Ledger app. Thus, I conclude with a different prefix/suffix as the signmessage NeoLine is using for Neo Legacy it should be possible to do the same for N3, no?

@hacfox
Copy link

hacfox commented Aug 11, 2023

@csmuller Whether it can be done or not is one thing, but first, consider this: for developers, they are more inclined to perform actions like:

data = crypto.sign(message, privatekey);  // message = neow3j is awesome!

and

crypto.verify(data, publickey);

Rather than the current situation where rules and strings are added before and after, causing confusion among developers.

@hacfox
Copy link

hacfox commented Aug 11, 2023

@csmuller And...
As you mentioned, For N3, we construct the message in a transaction-like format for the Ledger to sign (without sending it to nodes). This is indeed feasible, and we have actually accomplished this quite early on. However, we have been weighing the pros and cons of this approach and haven't integrated it into the existing code yet. You won't find it in any branch on GitHub either. If you need, I can provide something, FYI. 👇

const message = 'hello world';
const parameterHexString = Buffer.from(message).toString('hex');
const lengthHex = u.num2VarInt(parameterHexString.length / 2);
const concatenatedString = lengthHex + parameterHexString;
const prefix =  000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000;
const messageHex = prefix + concatenatedString;
const signHex = u.num2hexstring(0, 4, true) + u.sha256(messageHex); // u.num2hexstring(0, 4, true) is MagicNumber, set 0 here

const signData = wallet.sign(signHex, privateKey); 
const result = wallet.verify(signHex, signData, publicKey); 

prefix:
00  verison
00000000  nonce
0000000000000000  systemFee
0000000000000000  networkFee
00000000  validUntilBlock
01 0000000000000000000000000000000000000000 00 signers: length is 1|account|scope
00 attributes: length is 0

Why prefix? Only for transaction-like format!

@mialbu mialbu removed their assignment Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants