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

[W3F Grant Milestone 2] ECDSA Custom Signature Pallet Hardware Wallet Support UI implementation #5903

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

hoonsubin
Copy link
Contributor

@hoonsubin hoonsubin commented Aug 2, 2021

Note: This pull request is a clean version of #4435
There is an issue with reading error callbacks in MetaMask extension keyring manager. This issue must be resolved for this pull request to be ready for review (more about that from this thread)

Feature Summary

This feature is related to the Web3 Foundation grant milestone

Adds Custom Signature page under the Account tab.
The Custom Signature page allows the user to submit a transaction that was signed with an Ethereum private key and use it as a native ss58 encoded ECDSA account for Substrate. You can use MetaMask for signature requests, which allows users to use their Ethereum accounts from Ledger and Trezor to create transactions and execute runtime calls.

Preview

Ledger

ecdsa-sig-final.mp4

Trezor

ecdsa-sig-trezor.mov

IMG_0796

Screen Shot 2021-01-15 at 1 06 30 AM

Notable Changes

Usage

Currently, this page is made with MetaMask in mind. Most browser-injected ethereum wallets that use the window.ethereum object and accept the personal_sign method should be compatible, but please understand that there may be unexpected errors.

You can learn more about the usage from the official documentation: https://docs.astar.network/build/metamask-signatures

hoonsubin and others added 7 commits January 18, 2022 18:13
* Adding custom signature module integration for UI

[note]: this pull request was merged to clean the bloating commits done to this branch

* boilerplate work for making a new page

* added ethereum provider hooks (wip)

* added assert polyfil and eth signature recovery

* reset error message

* improved address change event handler

* added custom signature call (WIP)

* changed ecdsa address view component

* changed call encoding

* added dynamic chain address format

* fixed account switch handler

* compress recovered public key

* added transaction confirmation modal

* boilerplate work for making a new page

* added ethereum provider hooks (wip)

* added assert polyfil and eth signature recovery

* reset error message

* improved address change event handler

* added custom signature call (WIP)

* changed ecdsa address view component

* changed call encoding

* added dynamic chain address format

* fixed account switch handler

* compress recovered public key

* added transaction confirmation modal

* updated react component package version

* fixed dependencies list

* fixed linting and package version

* fixed package version and linting

* updated package version

* package resolution

* marked error

* fix error message parsing

needs testing

* add response message check

* update package version

* update local package

* update package version

* update package version

* refactor signature req method

* add null checks

* update package ver and copyright year

* fix license information
@hoonsubin
Copy link
Contributor Author

Sorry for the messy commit history, I must have been drunk 😓
I can close this and open a clean one if you think that is better

@jacogr
Copy link
Member

jacogr commented Jan 18, 2022

We merge with squash merges, so it doesn’t affect anything. So if you are happy, I am happy :)

@hoonsubin
Copy link
Contributor Author

hoonsubin commented Jan 18, 2022

Screen Shot 2022-01-18 at 7 02 33 PM

@jacogr if it's not too much, can you help me with this error I'm having? After adding the custom page to tsconfig paths, I'm starting to see type errors related to onChange and isDisabled React component properties. Plus, the custom type page is not being read properly too. My guess is related to some package reference error or invalid configs.

I'm trying to finalize this PR and wrap things up for review :)

Here is the full error log:

packages/react-params/src/Param/Enum.tsx:99:11 - error TS2322: Type '{ onChange: ([{ isValid, value }]: RawParam[]) => void; overrides: ComponentMap | undefined; params: ParamDef[]; registry: Registry; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

99           onChange={_onChangeParam}
             ~~~~~~~~

packages/react-params/src/Param/Struct.tsx:43:9 - error TS2322: Type '{ onChange: (values: RawParam[]) => void; overrides: ComponentMap | undefined; params: ParamDef[]; registry: Registry; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

43         onChange={_onChangeParams}
           ~~~~~~~~

packages/react-params/src/Param/Tuple.tsx:39:9 - error TS2322: Type '{ onChange: (values: RawParam[]) => void; overrides: ComponentMap | undefined; params: ParamDef[]; registry: Registry; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

39         onChange={_onChangeParams}
           ~~~~~~~~

packages/react-params/src/Param/Vector.tsx:115:9 - error TS2322: Type '{ isDisabled: boolean; onChange: Dispatch<SetStateAction<RawParam[]>>; overrides: ComponentMap | undefined; params: ParamDef[]; registry: Registry; values: RawParam[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

115         isDisabled={isDisabled}
            ~~~~~~~~~~

packages/react-params/src/Param/VectorFixed.tsx:90:9 - error TS2322: Type '{ isDisabled: boolean; onChange: Dispatch<SetStateAction<RawParam[]>>; overrides: ComponentMap | undefined; params: ParamDef[]; registry: Registry; values: RawParam[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

90         isDisabled={isDisabled}
           ~~~~~~~~~~

packages/react-params/src/index.tsx:156:26 - error TS2345: Argument of type 'typeof Params' is not assignable to parameter of type 'ComponentType<WithTranslationProps>'.
  Type 'typeof Params' is not assignable to type 'ComponentClass<WithTranslationProps, any>'.
    Types of property 'getDerivedStateFromProps' are incompatible.
      Type '({ isDisabled, params, registry, values }: Props, prevState: State) => Pick<State, never> | null' is not assignable to type 'GetDerivedStateFromProps<WithTranslationProps, any>'.
        Types of parameters '__0' and 'nextProps' are incompatible.
          Type 'Readonly<WithTranslationProps>' is missing the following properties from type 'Props': params, t, tReady

156 export default translate(Params);
                             ~~~~~~

packages/react-components/src/Call.tsx:98:9 - error TS2322: Type '{ isDisabled: true; onError: (() => void) | undefined; params: Param[]; registry: Registry; values: Value[]; withBorder: boolean | undefined; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

98         isDisabled
           ~~~~~~~~~~

packages/react-components/src/Event.tsx:70:9 - error TS2322: Type '{ children: Element | null; isDisabled: true; params: { type: TypeDef; }[]; values: { isValid: boolean; value: Codec; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

70         isDisabled
           ~~~~~~~~~~

packages/react-components/src/Event.tsx:82:15 - error TS2322: Type '{ isDisabled: true; params: AbiParam[]; values: Value[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

82               isDisabled
                 ~~~~~~~~~~

packages/react-components/src/Extrinsic.tsx:104:9 - error TS2322: Type '{ key: string; onChange: Dispatch<SetStateAction<RawParam[]>>; onEnter: (() => void) | undefined; onEscape: (() => void) | undefined; overrides: ComponentMap; params: { ...; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

104         onChange={setValues}
            ~~~~~~~~

packages/page-contracts/src/shared/Params.tsx:42:7 - error TS2322: Type '{ isDisabled: boolean | undefined; onChange: (values: RawParams) => void; onEnter: (() => void) | undefined; params: ParamDef[]; registry: Registry; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

42       isDisabled={isDisabled}
         ~~~~~~~~~~

packages/page-democracy/src/Overview/TreasuryCell.tsx:70:9 - error TS2322: Type '{ children: Element[]; isDisabled: true; params: Param[]; values: Value[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

70         isDisabled
           ~~~~~~~~~~

packages/apps-routing/src/custom-signature.ts:7:23 - error TS2307: Cannot find module '@polkadot/app-custom-signature' or its corresponding type declarations.

7 import Component from '@polkadot/app-custom-signature';
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

packages/page-explorer/src/BlockInfo/Justifications.tsx:31:7 - error TS2322: Type '{ isDisabled: true; params: { type: TypeDef; }[]; values: { isValid: boolean; value: Codec; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

31       isDisabled
         ~~~~~~~~~~

packages/page-explorer/src/BlockInfo/Logs.tsx:23:7 - error TS2322: Type '{ isDisabled: true; params: { type: TypeDef; }[]; values: { isValid: boolean; value: Raw; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

23       isDisabled
         ~~~~~~~~~~

packages/page-explorer/src/BlockInfo/Logs.tsx:42:7 - error TS2322: Type '{ isDisabled: true; params: { name: string; type: TypeDef; }[]; values: { isValid: boolean; value: Codec; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

42       isDisabled
         ~~~~~~~~~~

packages/page-explorer/src/BlockInfo/Logs.tsx:60:7 - error TS2322: Type '{ isDisabled: true; params: { type: TypeDef; }[]; values: { isValid: boolean; value: Codec; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

60       isDisabled
         ~~~~~~~~~~

packages/page-explorer/src/BlockInfo/Logs.tsx:80:7 - error TS2322: Type '{ isDisabled: true; params: { name: string; type: TypeDef; }[]; values: { isValid: boolean; value: Codec; }[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'isDisabled' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

80       isDisabled
         ~~~~~~~~~~

packages/page-rpc/src/Rpc/Selection.tsx:91:9 - error TS2322: Type '{ key: string; onChange: (values: RawParam[]) => void; params: ParamDef[]; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

91         onChange={_onChangeValues}
           ~~~~~~~~

packages/page-storage/src/Selection/Modules.tsx:196:11 - error TS2322: Type '{ key: string; onChange: (values: RawParams) => void; onEnter: () => void; params: ParamsType; values: RawParams | null | undefined; }' is not assignable to type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.
  Property 'onChange' does not exist on type 'IntrinsicAttributes & Omit<Subtract<WithTranslationProps | (WithTranslationProps & { children?: ReactNode; }), WithTranslationProps>, keyof WithTranslation<...>> & WithTranslationProps & { ...; }'.

196           onChange={_onChangeValues}
              ~~~~~~~~


Found 20 errors.

@jacogr
Copy link
Member

jacogr commented Jan 18, 2022

Will take a peek in the morning EU time.

@jacogr
Copy link
Member

jacogr commented Jan 19, 2022

Change to tsconfig.base.json to fix eslint -

Original:

      "@polkadot/app-council": ["page-council/src"],
      "@polkadot/app-council/*": ["page-council/src/*"],
      "@polkadot/app-custom-signature/*": ["page-custom-signature/src/*"],

New: (Addition of root import)

      "@polkadot/app-council": ["page-council/src"],
      "@polkadot/app-council/*": ["page-council/src/*"],
      "@polkadot/app-custom-signature": ["page-custom-signature/src"],
      "@polkadot/app-custom-signature/*": ["page-custom-signature/src/*"],

yarn.lock Outdated Show resolved Hide resolved
@hoonsubin
Copy link
Contributor Author

Thanks @jacogr for the help! Everything is working well!

@hoonsubin hoonsubin marked this pull request as ready for review January 19, 2022 10:25
@jacogr
Copy link
Member

jacogr commented Mar 18, 2022

O, hell. Now I see it is not in draft anymore and needs a review. And 2 months ago as well. Sorry about that, the draft -> ready status changes always create and issue for me.

@lgtm-com
Copy link

lgtm-com bot commented Jul 15, 2022

This pull request introduces 1 alert when merging 00e1b6b into 56087a7 - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

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

Successfully merging this pull request may close these issues.

6 participants