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

Add support for NearMobileWallet #931

Merged
merged 13 commits into from
Oct 19, 2023
Merged

Add support for NearMobileWallet #931

merged 13 commits into from
Oct 19, 2023

Conversation

GuillemGarciaDev
Copy link
Contributor

@GuillemGarciaDev GuillemGarciaDev commented Sep 15, 2023

Description

Please include a summary of the wallet and how users can install it. Be sure to take a look at our guide on Custom Wallets to understand core concepts when integrating with Wallet Selector.

Summary

In order to onboard customers with our wallet, this PR intends to connect NearMobileWallet with Wallet Selector. Users of the Near Mobile wallet may safely store, manage, and send NEAR and other cryptocurrencies while on the go. Non-custodial mobile wallet that is simple to use.

PR summary

This PR contains the integration with Wallet selector. To achieve it, a package has been added to package.json file (@peersyst/near-mobile-signer) to handle the requests.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@GuillemGarciaDev GuillemGarciaDev changed the title Dev NearMobileWallet integration Sep 15, 2023
@HarisSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,

I try to run this PR, and I can see wallet in list, but when I try to open it, I can't see QR code there.

@erditkurteshiSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,
Thank you for raising this PR.

While trying to login with near mobile wallet we noticed a QR code shown in the modal.
Can you explain how to scan the QR code, on the mobile app there is no place to scan it.

image

@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev , Thank you for raising this PR.

While trying to login with near mobile wallet we noticed a QR code shown in the modal. Can you explain how to scan the QR code, on the mobile app there is no place to scan it.

image

Hi @erditkurteshiSQA!
We are preparing the version of the wallet with the new functionality. Once it is updated, you will be able to scan the QR using a scan button on the bottom bar.

When the version is uploaded I will notify you so you can test it.

Thanks for your quick reply!

@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev ,

I try to run this PR, and I can see wallet in list, but when I try to open it, I can't see QR code there.

Hi @HarisSQA !

When you click on the wallet, does a modal appear or nothing at all?

Thanks for the feedback!

@HarisSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,
I try to run this PR, and I can see wallet in list, but when I try to open it, I can't see QR code there.

Hi @HarisSQA !

When you click on the wallet, does a modal appear or nothing at all?

Thanks for the feedback!

Hi @GuillemGarciaDev ,

I had an issue only with the QR code. Modal was working fine.

Also, I have tested it now, and the QR code is shown in modal.

@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev ,
I try to run this PR, and I can see wallet in list, but when I try to open it, I can't see QR code there.

Hi @HarisSQA !
When you click on the wallet, does a modal appear or nothing at all?
Thanks for the feedback!

Hi @GuillemGarciaDev ,

I had an issue only with the QR code. Modal was working fine.

Also, I have tested it now, and the QR code is shown in modal.

Hello!

Sorry for taking so long to reply. @HarisSQA we are trying to replicate your case! Thanks for the feedback.

Possibly tomorrow or the day after you will have the new version of the app available to test the wallet connector with the wallet. @HarisSQA @erditkurteshiSQA

When it's up I'll notify you!

Thanks again!

@GuillemGarciaDev
Copy link
Contributor Author

Hi! @HarisSQA @erditkurteshiSQA

The new version of NEAR Mobile wallet has been uploaded to the stores, so you can now test the PR properly. Once you import an account, you will find a scan button on the bottom bar of the app that will allow you to scan QRs.

I'll keep an eye out for any feedback.
Thanks again

@erditkurteshiSQA
Copy link
Contributor

erditkurteshiSQA commented Oct 4, 2023

Hi @GuillemGarciaDev ,

We have tested the wallet with the latest release of the app.
I tested it with importing two different accounts and also creating one.
Noticed a problem while scanning the QR code.

Take a look at the picture below:

Screenshot_20231004_161722.jpg

packages/near-mobile-wallet/assets/icon.png Outdated Show resolved Hide resolved
packages/near-mobile-wallet/jest.config.ts Outdated Show resolved Hide resolved
packages/near-mobile-wallet/package.json Outdated Show resolved Hide resolved
packages/near-mobile-wallet/project.json Outdated Show resolved Hide resolved
@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev ,

We have tested the wallet with the latest release of the app. I tested it with importing two different accounts and also creating one. Noticed a problem while scanning the QR code.

Take a look at the picture below:

Screenshot_20231004_161722.jpg

Hi @erditkurteshiSQA!

The issue is now fixed! It was a missing env variable. I tested the guest-book locally with the app and it seems to be working fine.

All requested PR changes have been fixed!

Regards, Guillem

@erditkurteshiSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,
Thank you for the quick fix.

We were able to log in with iOS and tested it. However, the signMessage feature is not working, and I will provide a picture below of the error:

image

Also, we noticed that if we close the QR modal while trying to connect with the wallet, we still see the message Connecting to Near Mobile Wallet instead of a different message or an error message indicating that the modal is closed.

image

On Android, however, on the Play Store, it's still the older version of the wallet, and the login problem still persists.

Play Store app version: 1.3.0
App Store app version: 2.3.0

],
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx"],
coverageDirectory: "../../coverage/packages/ramper-wallet",
Copy link
Contributor

@erditkurteshiSQA erditkurteshiSQA Oct 6, 2023

Choose a reason for hiding this comment

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

Can you please update the coverageDirectory to the near-mobile-wallet?

@GuillemGarciaDev
Copy link
Contributor Author

Hi @HarisSQA !

We have been working on the Android issue and it is already solved. You will be able to test it when it is in Play store. 👍🏻

On the other hand, could you provide me some info about how the signed message is verified? What we do is to verify the signature using the public key of the account.

const { publicKey, signature, accountId } = response;
const sign = new Uint8Array(Buffer.from(signature, "base64"));
const messageHash = new Uint8Array(sha256.digest(`NEP0413:${JSON.stringify({ receiver, message })}`));
const isValidSignature = PublicKey.fromString(publicKey).verify(messageHash, sign);

Thank you for your feedback!

@erditkurteshiSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,

Please refer to the example referenced here in the NEP:
https://github.com/near/NEPs/blob/master/neps/nep-0413.md#references

This is how the message needs to be serialized and signed in the wallet:
https://github.com/gagdiez/near-login/blob/main/tests/authentication/wallet.ts#L60

This is how we verify on our examples:
https://github.com/near/wallet-selector/blob/main/examples/react/components/Content.tsx#L289

Looks like you have implemented some kind of an old version of the sign message looking at this line of code:
const messageHash = new Uint8Array(sha256.digest(NEP0413:${JSON.stringify({ receiver, message })}));

The NEP413 does not add a prefix string NEP0413 to the message now it uses a tag (number) there's no receiver either please see the interface:
https://github.com/near/NEPs/blob/master/neps/nep-0413.md#input-interface

Message must be signed with the above structure with params ordered alphabetically for the required params.

@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev ,

Please refer to the example referenced here in the NEP: https://github.com/near/NEPs/blob/master/neps/nep-0413.md#references

This is how the message needs to be serialized and signed in the wallet: https://github.com/gagdiez/near-login/blob/main/tests/authentication/wallet.ts#L60

This is how we verify on our examples: https://github.com/near/wallet-selector/blob/main/examples/react/components/Content.tsx#L289

Looks like you have implemented some kind of an old version of the sign message looking at this line of code: const messageHash = new Uint8Array(sha256.digest(NEP0413:${JSON.stringify({ receiver, message })}));

The NEP413 does not add a prefix string NEP0413 to the message now it uses a tag (number) there's no receiver either please see the interface: https://github.com/near/NEPs/blob/master/neps/nep-0413.md#input-interface

Message must be signed with the above structure with params ordered alphabetically for the required params.

There's a new version in the Play Store to try out wallet selector in Android! There's a new update on the signMessage feature and it is now working!

@erditkurteshiSQA
Copy link
Contributor

Hi @GuillemGarciaDev ,

We checked the latest iOS and android version and the functionalities are working including signMessage but
there are some issues/improvement that require attention:

  1. All Reject(s) are being ignored, and the promise never resolves.
  2. Open the wallet-selector modal and click on NearMobileWallet to open the QR code modal. However, closing the QR code modal does not trigger the expected rejection of the signIn request.
  3. When signing in, trying signAndSendTransaction(s) and scanning the QR code, the rejection on the wallet does not trigger any action. It should reject the signAndSendTransaction by throwing an error.
  4. Add the ability for local signing for FunctionCall transactions without a deposit. Currently, the wallet creates a Limited Access Key (LAK) but does not utilize it.
  5. Multiple-transactions should be able to be signed just by signing the QR code once.

As a suggestion consider comparing the UX of wallet-selector with Here wallet, since both wallets are mobile wallets.

@AdriaCarrera
Copy link

AdriaCarrera commented Oct 16, 2023

Hi @GuillemGarciaDev ,

We checked the latest iOS and android version and the functionalities are working including signMessage but there are some issues/improvement that require attention:

  1. All Reject(s) are being ignored, and the promise never resolves.
  2. Open the wallet-selector modal and click on NearMobileWallet to open the QR code modal. However, closing the QR code modal does not trigger the expected rejection of the signIn request.
  3. When signing in, trying signAndSendTransaction(s) and scanning the QR code, the rejection on the wallet does not trigger any action. It should reject the signAndSendTransaction by throwing an error.
  4. Add the ability for local signing for FunctionCall transactions without a deposit. Currently, the wallet creates a Limited Access Key (LAK) but does not utilize it.
  5. Multiple-transactions should be able to be signed just by signing the QR code once.

As a suggestion consider comparing the UX of wallet-selector with Here wallet, since both wallets are mobile wallets.

Hi @erditkurteshiSQA and @HarisSQA it's Adrià from Peersyst team, thanks for all this feedback.

We have almost all the points that you mentioned done, except the 4th one. Is it something that you require to be done before getting approved or we can merge without this point and make an improvement later on? Also could you point us to some links or docs that better explain the local signing?

Thank you!

@erditkurteshiSQA
Copy link
Contributor

erditkurteshiSQA commented Oct 16, 2023

Hey @AdriaCarrera

The 4th point is being mentioned as an improvement and can be done later on once the other points are working fine.

The idea is to be able to sign FunctionCall transactions that don't have any deposit without confirming it on the Wallet since the FunctionCall Access-key (limited access key LAK) is on the localStorage of when we sign in with NearMobileWallet, this improves the UX.

Looks like you save the LAK in near-mobile-signer:session

For instance, one use case of such a transaction is the ability to send messages in our guest book example without needing confirmation in the wallet when no deposit is attached.

This approach is also implemented in near-api-js as demonstrated here:
https://github.com/near/near-api-js/blob/master/packages/wallet-account/src/wallet_account.ts#L306

In our wallet-connect package, we have a simpler version, as shown in here:
https://github.com/near/wallet-selector/blob/main/packages/wallet-connect/src/lib/wallet-connect.ts#L558-L566

The exact implementation might differ but the core idea is the same, I believe a similar approach can be implemented in the @peersyst/near-mobile-signer package.

If you need any more information or have more questions, feel free to reach out.

Thank you!

@erditkurteshiSQA
Copy link
Contributor

Hi @GuillemGarciaDev @AdriaCarrera ,

Following the recent update on the Near mobile wallet and this PR, we tested it on both iOS and Android.
We are unable to login in both platforms. Please refer to the attached image for the error:
image

Additionally, kindly remember that the 4th point, mentioned earlier, is considered an improvement and can be addressed once the other points are resolved.

Thank you!

@GuillemGarciaDev
Copy link
Contributor Author

Hi @GuillemGarciaDev @AdriaCarrera ,

Following the recent update on the Near mobile wallet and this PR, we tested it on both iOS and Android. We are unable to login in both platforms. Please refer to the attached image for the error: image

Additionally, kindly remember that the 4th point, mentioned earlier, is considered an improvement and can be addressed once the other points are resolved.

Thank you!

Hi @erditkurteshiSQA !!

This issue seems already fixed and you have available a new version with all the improvements (except the 4th one). I hope you find this fixes working as expected!

Thank you again!!

@erditkurteshiSQA erditkurteshiSQA changed the title NearMobileWallet integration Add support for NearMobileWallet Oct 19, 2023
@erditkurteshiSQA
Copy link
Contributor

@GuillemGarciaDev

After testing the wallet with the latest version in both platform, all issues have been successfully resolved. We are now ready to merge this PR.
A release is planned for tomorrow, which will include the changes from this PR.

Thank you!

@erditkurteshiSQA erditkurteshiSQA merged commit 00c56e9 into near:dev Oct 19, 2023
7 checks passed
@kujtimprenkuSQA
Copy link
Contributor

Hi, @GuillemGarciaDev & @AdriaCarrera we have published a new version of the wallet-selector:

Release notes: https://github.com/near/wallet-selector/releases/tag/v8.7.0

Near Mobile Wallet: https://www.npmjs.com/package/@near-wallet-selector/near-mobile-wallet

@kujtimprenkuSQA
Copy link
Contributor

kujtimprenkuSQA commented Oct 27, 2023

Hi, @GuillemGarciaDev & @AdriaCarrera could you please take a look at the issues that need improvement:

  • The @peersyst/near-mobile-signer has too many unnecessary dependencies:
    https://www.npmjs.com/package/@peersyst/near-mobile-signer?activeTab=dependencies
    Can you please improve the bundler to include only the necessary dependencies and remove all devDependencies from NPM? - they get added to dApps which is not ideal.

  • Passing a callbackUrl for signMessageparams is failing can you take a look at it too?

  • The QR Code of NearMobileWallet does not open correctly when other extensions are installed such as MetaMask, Nightly, Sender etc see below video:

qr-code-issue-near-mobile-wallet.webm

@GuillemGarciaDev
Copy link
Contributor Author

Hi, @GuillemGarciaDev & @AdriaCarrera could you please take a look at the issues that need improvement:

  • The @peersyst/near-mobile-signer has too many unnecessary dependencies:
    https://www.npmjs.com/package/@peersyst/near-mobile-signer?activeTab=dependencies
    Can you please improve the bundler to include only the necessary dependencies and remove all devDependencies from NPM? - they get added to dApps which is not ideal.
  • Passing a callbackUrl for signMessageparams is failing can you take a look at it too?
  • The QR Code of NearMobileWallet does not open correctly when other extensions are installed such as MetaMask, Nightly, Sender etc see below video:

qr-code-issue-near-mobile-wallet.webm

Hi! @kujtimprenkuSQA we are working to fix these issues.

About callbackUrl issue, since NearMobileWallet is an InjectedWallet there's no reason to use a callbackUrl because the signature action is done in a mobile app.

Should we create a new PR with the new fixes?

Thank you for your feedback!

@kujtimprenkuSQA
Copy link
Contributor

Hi, @GuillemGarciaDev & @AdriaCarrera could you please take a look at the issues that need improvement:

  • The @peersyst/near-mobile-signer has too many unnecessary dependencies:
    https://www.npmjs.com/package/@peersyst/near-mobile-signer?activeTab=dependencies
    Can you please improve the bundler to include only the necessary dependencies and remove all devDependencies from NPM? - they get added to dApps which is not ideal.
  • Passing a callbackUrl for signMessageparams is failing can you take a look at it too?
  • The QR Code of NearMobileWallet does not open correctly when other extensions are installed such as MetaMask, Nightly, Sender etc see below video:

qr-code-issue-near-mobile-wallet.webm

Hi! @kujtimprenkuSQA we are working to fix these issues.

About callbackUrl issue, since NearMobileWallet is an InjectedWallet there's no reason to use a callbackUrl because the signature action is done in a mobile app.

Should we create a new PR with the new fixes?

Thank you for your feedback!

Yes, a new PR should be made once the QR Code issue is fixed and also the dependencies for @peersyst/near-mobile-signer

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