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

Implement signRaw #196

Merged
merged 1 commit into from Dec 6, 2019
Merged

Implement signRaw #196

merged 1 commit into from Dec 6, 2019

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Nov 18, 2019

Fixes #115

With the following interface:

export interface RequestSign {
  inner: SignerPayloadJSON | SignerPayloadRaw;
  sign(pair: KeyringPair): { signature: string };
}

extension package abstracts the signing procedure using the sign method and because extension-ui needs to be aware if it is dealing with an extrinsic or a bunch of bytes, inner returns the inner payload content of its implementations.

@jacogr
Copy link
Member

jacogr commented Nov 19, 2019

Thanks for doing this, this is a great addition. I will take a look in the next couple of hours.

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, thank you very much for this. I only have some really small nitpick-y comments.

packages/extension-ui/src/Popup/Signing/Request.tsx Outdated Show resolved Hide resolved
packages/extension/src/background/types.ts Show resolved Hide resolved
packages/extension/src/background/handlers/Tabs.ts Outdated Show resolved Hide resolved
packages/extension-ui/src/Popup/Signing/Request.tsx Outdated Show resolved Hide resolved
@c410-f3r
Copy link
Contributor Author

Code updated. Thanks for reviewing

@c410-f3r
Copy link
Contributor Author

@jacogr I tested the implementation manually and fixed some issues

@jacogr
Copy link
Member

jacogr commented Nov 23, 2019

Thanks for that, it is the only thing I was still missing to merge - I have it top of the list for the morning. (I am truly sorry for the long delay between the PR and merge here, not quite cool seeing thing stuck, so my humble apologies)

@jacogr
Copy link
Member

jacogr commented Nov 24, 2019

Via this one, polkadot-js/apps#1936, the signature comes back as bytes instead of hex -

image

It should be hex. (Just need to pass the response through u8aToHex)

@c410-f3r
Copy link
Contributor Author

Updated

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

Thank you. Will do the final play-through this morning, really excited to get this in.

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

A couple of issues -

  1. When I sign text, e.g. hello it works. When I sign hex data e.g. 0x123456 the signature does not match. I believe it is due to the fact that we pass the data through the TextEncoder - we should just pass the raw input data

  2. When I try and send an extrinsic, pub(extrinsic.sign) passed, it still brings up the bytes signing dialog.This is a screenshot of the 2, the first being the current extrinsic, the second being actual bytes

image

  1. The text styling for from & bytes above does not match up with the actual old extinsic display and looks out of place. Compare the above against this -

image

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

I have merged support for this on the apps UI, so this feature should be easier to test and explore now.

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Nov 25, 2019

WTF! So much problems. Sorry for the noise.
The code has been updated to reflect the issues

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

This one is tough to test properly without having some way of well, testing :) So no reason to apologize, I also looked at the code and well, that looks good - however, you were playing in the depths of midnight, so those excursions are never easy.

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Nov 25, 2019

This one is tough to test properly without having some way of well, testing :) So no reason to apologize, I also looked at the code and well, that looks good - however, you were playing in the depths of midnight, so those excursions are never easy.

Indeed! These are good examples of a programmer's life


sign (pair: KeyringPair): { signature: string } {
const inner = this.inner as SignerPayloadRaw;
const signedBytes = pair.sign(hexToU8a(inner.data));
Copy link
Contributor Author

@c410-f3r c410-f3r Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the SignerPayloadRawBase contract,

export interface SignerPayloadRawBase {
    /**
     * @description The hex-encoded data for this request
     */
    data: string;
    /**
     * @description The type of the contained data
     */
    type?: 'bytes' | 'payload';
}

data will always be hex, so it is up to the caller to pass valid data.

Also, type?: 'bytes' | 'payload'; doesn't make sense. One can simply const bytes = extrinsic.toU8a(true) and signRaw(bytes). Can we remove it?

Copy link
Member

@jacogr jacogr Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload was added specifically for other extensions, such as the centrality one - where they don't care about de-serliazing the payload, but rather just want to sign it as a raw blob. From an implementation perspective, both can just be treated as bytes here, it does not need to be treated separately for the case where signRaw is called.

The reason behind it - in case of transactions, the API will first try to use the normal payload sign, if that is not available will fallback to signRaw. Since the normal sign path is catered for, we should not receive a payload in normal circumstances.

Either way, it it ever does receive a type: payload it actually cannot quite decode it, since it is in a signable form, not a decodable form, so it should be treated it as a "piece of data". (There is a small trick here which came in with v4 where the signature needs to have type information attached in the case of a payload, but we don't need to cater for it here in signRaw)

TL;DR Ignore the type specifier on signRaw, we can just treat all data as bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting, thank you for writing this in an explanatory way

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

I'll need to take a peek again at the code here, since something is going wrong, either in the extension or somewhere along the way, i.e. possibly the UI doing something weird now that it has signRaw?

When submitting a transaction (verified against current, it doesn't happen), the transactions come through as "immortal", not "mortal with era", while the API def submits mortals. ... Update, after checking some more - the decoding is def. completely wrong, since here we have chain with version 195 and 194 displayed on the extension (in addition to the mortal being diaplyed as immortal being wrong)

image

Not sure, will take a peek though both sides again.

Additionally, the hex signing works, but I mucked-up the apps UI side for signing, i.e. when non-hex data inputted there, it doesn't send hex through. That needs a fix on that side, fix incoming.

@jacogr
Copy link
Member

jacogr commented Nov 25, 2019

So the issue with transactions is twofold -

  • the request is wrongly displayed, i.e. the mortal information is missing, which indicated the decoding was not properly done
  • the generated signature fails, i.e. the transaction cannot be submitted

(Both these are verified on an older version as working on the same chain)

I believe is is due to how inner is constructed. So rather,

With the above change reverted, at least the signing portion should still work, I'm trying to figure . out wht the .inner and cast makes the decoding not work in . the way it was.

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signRaw portion seems 100% now, however some small issues with transaction signing snuck in.

@c410-f3r c410-f3r force-pushed the sign-raw branch 2 times, most recently from 07a7240 to 1293466 Compare November 30, 2019 00:25
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Nov 30, 2019

My recent sickness plus some other responsibilities temporally took out my motivation to work on this PR, thus the delay.

Well, back on track. Here is a screenshot of a correctly displayed substrate transaction info.

Capture d’écran de 2019-11-29 20-23-41

And another showing the same transaction successfully registered.

Capture d’écran de 2019-11-29 20-25-02

@jacogr
Copy link
Member

jacogr commented Nov 30, 2019

Thank you !

Hope you are doing ok.

@jacogr
Copy link
Member

jacogr commented Dec 2, 2019

Sorry, I'm very aware I need a play-through and review here ASAP. Just "a bit" snowed under after the Kusama CC3 launch. So need to, want to, I just have not had a gap.

My humble apologies for dragging my feet, not out of choice.

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 2, 2019

@jacogr

Don't worry about it, we all have stuff to do. Personally, you are one of the most attentive reviewers I have ever met

@jacogr
Copy link
Member

jacogr commented Dec 5, 2019

I will take a play through today, thanks for the patience on this :(

Copy link
Member

@jacogr jacogr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely brilliant! Thanks a million for this, it does exactly what it says on the tin. Tested against CC3 with transfers, signing (bytes & strings), all 100% ok.

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 6, 2019

This is awesome! Thanks!

@jacogr jacogr mentioned this pull request Dec 6, 2019
@jacogr jacogr merged commit 411e1f1 into polkadot-js:master Dec 6, 2019
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 6, 2019

@jacogr Do you know when will be next marketplace deployment?

@jacogr
Copy link
Member

jacogr commented Dec 6, 2019

I will do it soon - I am just stuck with a nasty flu atm, so don’t quite trust a release process. So just need an update to latest Kusama CC3 and a full test through.

I am hoping in the next couple of days (hopefully latest on Monday), I just need a clear head. ;)

@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 7, 2019

Flu catches us all. Hope you get better
Thanks for the information!

@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement signRaw Signer interface
3 participants