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

Tesseract dApps/Wallet integration native mobile libraries proposal #1856

Merged
merged 1 commit into from
Aug 15, 2023

Conversation

dileping
Copy link
Contributor

@dileping dileping commented Jul 19, 2023

Project Abstract

This follow-up grant proposal aims to reduce the integration barriers of the mobile dApp/Wallet integration protocol built during the previous grant.

Tesseract dApp/Wallet integration protocol implemented in our previously finished grant provides excellent UX enhancement capabilities to the Polkadot Substrate ecosystem. Its current version allows native mobile applications to request public keys and transaction signatures through seamless integration with any Tesseract-compatible wallet installed on the same smartphone. You can see the Polkadoot dApp interacting with a wallet demo here: https://www.youtube.com/watch?v=0AlDYB3Qglc.

Though, to start providing value to the Polkadot/Substrate community, we need to lower the current technical integration barriers. Tesseract is built in Rust for its reliability, robustness, and cross-platform nature. While being a great benefit, it also imposes a technical barrier by being labor-intensive to integrate into mobile dApps and Wallets. To eliminate this, we propose to build a set of native Swift and Kotlin libraries that wrap Tesseract’s Rust implementation under the hood and provide mobile developers with a straightforward way to integrate Tesseract within minutes, thus significantly improving the UX of mobile dApps within Polkadot/Substrate ecosystem.

Application Checklist

  • The application template has been copied and aptly renamed (dapp_wallet_integration_native_mobile_libraries.md).
  • I have read the application guidelines.
  • Payment details have been provided (bank details via email or BTC, Ethereum (USDC/DAI) or Polkadot/Kusama (USDT) address in the application).
  • The software delivered for this grant will be released under an open-source license specified in the application.
  • The initial PR contains only one commit (squash and force-push if needed).
  • The grant will only be announced once the first milestone has been accepted (see the announcement guidelines).
  • I prefer the discussion of this application to take place in a private Element/Matrix channel. My username is: @_______:matrix.org (change the homeserver if you use a different one)

@CLAassistant
Copy link

CLAassistant commented Jul 19, 2023

CLA assistant check
All committers have signed the CLA.

@keeganquigley keeganquigley self-assigned this Jul 27, 2023
@keeganquigley
Copy link
Contributor

Thanks for the application @dileping formatting looks good. A few initial questions:

  • For this grant I understand you will only be focusing on the prerequisite of the Swift/Kotlin Tesseract libraries. After this is complete, how do you plan to fund building the library for the Swift/Kotlin bridges for cross-platform frameworks?
  • A lot of software has been built since the completion of your previous grant 3 years ago. For example swift-bridge and SwiftWasm. Have you done research recently to ensure that these wrappers are still needed? Or any projects you can collaborate with?
  • Will the project integrate light clients at some point? For example in this forum post they debate the possibilities of being able to run Smoldot on mobile devices.

@dileping
Copy link
Contributor Author

dileping commented Jul 28, 2023

Thanks for the question, @keeganquigley. Please, see my comments below inline.

Thanks for the application @dileping formatting looks good. A few initial questions:

* For this grant I understand you will only be focusing on the prerequisite of the Swift/Kotlin Tesseract libraries. After this is complete, how do you plan to fund building the library for the Swift/Kotlin bridges for cross-platform frameworks?

I think there is some confusion here. Please, let me clarify.

The proposal is to build the fully functioning Swift and Kotlin libraries wrapping all the functionality of Tesseract. Not just the prerequisites. All the developers using the "default" approach for their mobile work will be able to use Tesseract just like any other library.

As for the cross-platform libraries (ReactNative, Flutter, etc.), we'd like to provide cross-platform developers to integrate Tesseract as easily as everybody else in the future. Though, there are a couple of points to consider:

  • cross-platform libraries need the Swift and Kotlin libraries built first anyway (I think this is the source of confusion here)
  • it's more important to provide the toolset for the default platform languages first (Swift for iOS, Kotlin for Android)

As for the funding of the cross-platform libraries - I think it's either through another grant or investor funding.

* A lot of software has been built since the completion of your previous grant 3 years ago. For example [swift-bridge](https://github.com/chinedufn/swift-bridge) and [SwiftWasm](https://swiftwasm.org/). Have you done research recently to ensure that these wrappers are still needed? Or any projects you can collaborate with?

I agree; a lot of progress has been made in the Rust interop. I was monitoring it from time to time and researched this topic before preparing the proposal. Despite the progress, I still find the projects lacking a lot of what we need (i.e., asynchronous communication).

While working on the previous grant, we developed a set of libraries that makes the interop process much easier. Here you can check them out:

These libraries provide us with pretty much everything we need and handle our edge cases very well. I think working around the limitations of other libraries will take more time and effort for us than doing how we have approached the interop so far.

Also, we are planning to extract them eventually and make them more friendly for other developers. So they should end up in separate repos soon.

* Will the project integrate light clients at some point? For example in this [forum post](https://forum.polkadot.network/t/developing-for-the-webkit-browser-engine/2940/8) they debate the possibilities of being able to run [Smoldot](https://github.com/paritytech/smoldot) on mobile devices.

Any client library (assuming it doesn't have private keys functionality hardcoded) can be used with Tesseract as a signature provider. Here is an example of how we did it for subxt in our Polkadot Chat dApp Demo: https://github.com/tesseract-one/polkachat.rs/blob/main/common/src/substrate/signer.rs

We thought about an idea to possibly provide ready-made Tesseract signature providers for the most popular Polkadot client libraries in the future.

@keeganquigley
Copy link
Contributor

keeganquigley commented Jul 28, 2023

Thanks @dileping for the thorough explanations. Regarding my first comment, yes I just wasn't sure if the prerequisites you mentioned were part of this grant or not. Thanks for your clarifications there.

I will mark the application as ready for review and ping the rest of the committee to take a look. I will also ping my colleague @CrackTheCode016 in case he has time and is able to give a quick review, as he is more familiar with Rust and mobile libraries than I.

@keeganquigley keeganquigley added the ready for review The project is ready to be reviewed by the committee members. label Jul 28, 2023
@dileping
Copy link
Contributor Author

Thanks @dileping for the thorough explanations. Regarding my first comment, yes I just wasn't sure if the prerequisites you mentioned were part of this grant or not. Thanks for your clarifications there.

I will mark the application as ready for review and ping the rest of the committee to take a look. I will also ping my colleague @CrackTheCode016 in case he has time and is able to give a quick review, as he is more familiar with Rust and mobile libraries than I.

Thanks for moving the status forward, @keeganquigley! Glad my explanations were clear. Will be happy to answer more questions as they come up.

Copy link
Contributor

@CrackTheCode016 CrackTheCode016 left a comment

Choose a reason for hiding this comment

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

Thank you for submitting! I have left a few comments. As I understand, this proposal aims to do the following:

Provide Substrate-specific wrappers for Tesseract, which will allow for chain-specific signing capabilities to be possible. Basically, allow someone to use Substrate signing and extrinsic construction libs in native mobile environments through IPC to whatever wallet contains the private key?

Thank you again!

1. Tesseract itself
2. IPC transport
3. Test protocol
4. Substrate protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

How much of Substrate would be wrapped here?

It seems to me, whatever is used in constructing extrinsics in something like like subxt would be most appropriate? (sp_core, sp_runtime, some SCALE stuff etc). Or will you wrap subxt directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't aim to wrap the subxt library. For the integration with Substrate, what we really need is a substrate-specific communication protocol. As for the integration with subxt, here is an example of how we did it in our demo apps: https://github.com/tesseract-one/polkachat.rs/blob/main/common/src/substrate/signer.rs

Also, we are providing a Substrate Swift library (not even a wrapper) for iOS developers so that they can use Substrate really easily together with Tesseract: https://github.com/tesseract-one/Substrate.swift/


1. Tesseract itself
2. IPC transport
3. Test protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies if it was mentioned, but what is "Test protocol"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test protocol is a communication protocol implemented in Tesseract on the same level as Substrate. It allows passing strings between the dApp and the Wallet and aims to be an easy way to test that Tesseract works correctly in the dApp or Wallet - whatever one tests at the moment.

```swift
let polkadotWalletService = Tesseract(delegate: delegate)
.transport(IPCTransportIOS())
.service(protocol: .polkadot)
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming this will also support other networks, i.e., Kusama, or other Substrate based chains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't test it with Kusama, but it is the goal. Theoretically, it should work with any chain built on top of the Substrate. We are going to make sure it's the case.

@dileping
Copy link
Contributor Author

Thank you for submitting! I have left a few comments. As I understand, this proposal aims to do the following:

Provide Substrate-specific wrappers for Tesseract, which will allow for chain-specific signing capabilities to be possible. Basically, allow someone to use Substrate signing and extrinsic construction libs in native mobile environments through IPC to whatever wallet contains the private key?

Thank you again!

Hi @CrackTheCode016, thanks for reviewing the proposal!

I think you can say so - allow mobile developers to use Substrate and use the signing capabilities of whatever wallets. That's the goal; however, I want to add some details which I believe should bring more clarity.

Actually, we have already implemented the Substrate chain-specific capabilities in Rust during the previous grant. Here is what the interface for the Substrate communication protocol looks like: https://github.com/tesseract-one/Tesseract.rs/tree/master/protocols/substrate. Currently, it's the only blockchain protocol we support, though more can be added fairly easily. Regarding the Substrate integration, within this grant proposal scope, we aim to provide Swift and Kotlin APIs for the protocol we already have.

However, the proposal is not limited to only wrapping the Substrate integration. Instead, it aims to provide the whole Tesseract together with Substrate protocol for the mobile native environment in the form of native libs: Kotlin and Swift. This is necessary because Tesseract is written in Rust, and although it's possible to use Rust in native mobile apps, it's hardly an easy and enjoyable process. As an example, please, take a look at two demos we created as a part of the previous grant (both using Tesseract in its Rust form):

  1. PolkaChat demo dApp - a simple, smart contract chat application that uses Tesseract for transaction signing.
  2. Develper Wallet - a wallet that we provide for the dApp developers to test their dApps working with Tesseract protocol easily.

Also, I will go ahead and comment inline on your review.

@CrackTheCode016
Copy link
Contributor

@dileping Thank you for the clarification!

Based on this, this will serve as native wrappers for Tesseract as a whole, which subsequently includes Substrate.

On a personal note, I don't see many native wallets in this ecosystem, but that is primarily due to the barrier to development (everything is either in Rust or Typescript), so cross-platform apps are de facto. As a former native app developer, there are many pros to native development from both a performance and security standpoint.

Re-light client support might become relevant to pass in other information (proof or finality justification) from wallets and/or light clients on the device (as this is the future of client-side in web3). As an example, it is not farfetched for wallets to effectively become light clients themselves.

Would you foresee Tesseract being able to provide this sort of support to dapps directly from this sort of setup?

@dileping
Copy link
Contributor Author

@CrackTheCode016, thanks for the detailed reply! Please, see my comments below.

@dileping Thank you for the clarification!

Based on this, this will serve as native wrappers for Tesseract as a whole, which subsequently includes Substrate.

Exactly!

On a personal note, I don't see many native wallets in this ecosystem, but that is primarily due to the barrier to development (everything is either in Rust or Typescript), so cross-platform apps are de facto. As a former native app developer, there are many pros to native development from both a performance and security standpoint.

I agree. There are some, but definitely not a lot. There are a couple of things I think are important as well for consideration here:

  1. I believe that once there is more tooling available, more native dApps and Wallets get developed. As I mentioned earlier, for that reason, we also have developed and recently released Substrate.swift. This library is also W3F grant funded.
  2. We are planning to provide cross-platform APIs wrappers as well. For mobile, it probably is going to be ReactNative and Flutter. For the dApp-side, maybe even something like Cordova support would be nice. However, to build cross-platform libs, we first need a native API anyway. Hence native API is a prerequisite to cross-platform.

Re-light client support might become relevant to pass in other information (proof or finality justification) from wallets and/or light clients on the device (as this is the future of client-side in web3). As an example, it is not farfetched for wallets to effectively become light clients themselves.

Would you foresee Tesseract being able to provide this sort of support to dapps directly from this sort of setup?

I think I started understanding what you and @keeganquigley are talking about when mentioning the light nodes. As I understand, you mean using Tesseract not only for querying pub keys and signing transactions but also to query other types of data from a local wallet/light node instead of querying a pub node, am I right? From a technical perspective - I think it's totally possible. I'd love to chat with you more about it and hear more details, like what use cases exactly you have encountered and what potential use scenarios you see. Sounds very interesting.

Copy link
Contributor

@dsm-w3f dsm-w3f left a comment

Choose a reason for hiding this comment

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

@dileping thank you for the application. I read the comments and the application. As far as I understood, the value added here is to have a native API to connect with Tesseract both in Kotlin/Swift. This could help native mobile developers to connect to some Polkadot wallet, in case Tesseract. However, I'm trying to understand why they would do that. There are other ways to connect with wallets using native interfaces. For example, they would wallet connect native kotlin or Swift SDK to connect to Nova Wallet or SubWallet. In this case, what would make the developer to select Tesseract instead of an approach like that?

Another doubt is the extent of the integration with Tesseract, what would be the functions/capabilities covered? Where you say all capabilities and features, what do you mean? I searched in the Tesseract examples and found three functions being used, I think would be more than that. Where we can figure out what exact capabilities we are talking about?

@dileping
Copy link
Contributor Author

Hi @dsm-w3f, thanks for the review! Please, see my comments below inline.

@dileping thank you for the application. I read the comments and the application. As far as I understood, the value added here is to have a native API to connect with Tesseract both in Kotlin/Swift.

I'd add to this that the added value is to provide the Substrate community with a realistic way to start using Tesseract. With just the Rust APIs available, it's a huge barrier because of the complexity of Rust interop. The way we want to approach it - that's totally correct - the main deliverables are Swift and Java libraries for the dApp and Wallet sides, providing wallet integration through the Tesseract protocol.

This could help native mobile developers to connect to some Polkadot wallet, in case Tesseract.

Not sure I understood you correctly. Just to ensure there is no misunderstanding: we don't plan to make our own wallet for production. Just the Developer Waller, which is made only for the developers to test their dApps easier. Instead, we want to provide the community wallets and dApps with a new integration option.

However, I'm trying to understand why they would do that. There are other ways to connect with wallets using native interfaces. For example, they would wallet connect native kotlin or Swift SDK to connect to Nova Wallet or SubWallet. In this case, what would make the developer to select Tesseract instead of an approach like that?

Can't disagree. Though, we believe there is a big room for improvement in how the dApps and Wallets play together. Tesseract brings its own perspective to solving the problem, which in our opinion, provides a superior user experience plus some other benefits. Here are a couple of links to the documents we've created that analyze how exactly Tesseract's approach is different and what improvements such an approach brings to the table:

Another doubt is the extent of the integration with Tesseract, what would be the functions/capabilities covered? Where you say all capabilities and features, what do you mean? I searched in the Tesseract examples and found three functions being used, I think would be more than that. Where we can figure out what exact capabilities we are talking about?

I think there is some confusion here. In the demo dApps, we didn't expose the Tesseract APIs directly to Kotlin or Swift. Instead, we opted for a "cross-platform app with a native UI." We have built the whole logic of the application in Rust and made a narrow point of contact between the thin UI layer and the Rust logic implementation. To make it clear - the example file you encountered is not a part of Tesseract's API, but rather how the UI and the Core (cross-platform part) of the example communicate with one another.

Tesseract Rust APIs are mainly located in the Tesseract.rs. There you can find the APIs in various groups. Firstly divided by the location where they are used:

  • Client (dApp side)
  • Service (Wallet side)

Secondly, divided by the API category:

  • main entry point
  • transports
  • connections
  • protocols
  • services
  • etc.

As for the examples of some use cases, I'd suggest, for starters going to the following subrepos where the Rust APIs are used directly in a dApp and a Wallet:

@semuelle semuelle added the closed process: private finances This application is not processed on GitHub. The team wishes its funding details to remain private. label Aug 2, 2023
@semuelle semuelle self-requested a review August 2, 2023 13:41
@dsm-w3f
Copy link
Contributor

dsm-w3f commented Aug 3, 2023

@dileping thank you for the answer. I understood that the Tesseract is an interconnection library between the Dapp and Wallet as WalletConnect is. Could you please give me more details on the affirmation "in our opinion, (Tesseract) provides a superior user experience plus some other benefits"? I read the application and saw that there are some characteristics that you claim that Tesseract could be better than other libs with the same purpose. Could you compare for example with WalletConnect, using native libs (see the links in my previous comment), and provide some of these characteristics that Tesseract could do that WalletConnect can't? Or in what way Tesseract is different from WalletConnect that could influence the decision of developers to use Tesseract and not WalletConnect?

@dileping
Copy link
Contributor Author

dileping commented Aug 4, 2023

@dileping thank you for the answer. I understood that the Tesseract is an interconnection library between the Dapp and Wallet as WalletConnect is. Could you please give me more details on the affirmation "in our opinion, (Tesseract) provides a superior user experience plus some other benefits"? I read the application and saw that there are some characteristics that you claim that Tesseract could be better than other libs with the same purpose. Could you compare for example with WalletConnect, using native libs (see the links in my previous comment), and provide some of these characteristics that Tesseract could do that WalletConnect can't? Or in what way Tesseract is different from WalletConnect that could influence the decision of developers to use Tesseract and not WalletConnect?

@dsm-w3f, thanks for the question! It's quite a challenge to provide you with a succinct answer here, but I'll do my best.

Tesseract does not aim to bring more features. Instead, it aims to do the dApp and Wallet interaction better. Even though from the technical perspective, Tesseract and WalletConnect are based on completely different technologies, and I'd love to start with it, let's rather jump first to some obvious consequences of the different technological choices:

  1. The UX:
  • Wallet connect requires some setup (selecting a wallet that the user wants to connect to from a big list). In contrast, Tesseract relies on the underlying operating system, which provides the user with the list of installed and compatible with the dApp wallets that the user has on the smartphone. The selection UI is provided by the OS itself at the moment the dApp sends the first request. Thus the UI is truly native and cohesive with the OS.
  • WalletConnect switches the apps to present the Wallet, while Tesseract allows the Wallet to present the UI as a "sheet" on top of the dApp, which looks more like a proper modal UX (which it truly is under the hood). Looks especially well on iOS. Again, more cohesive with the OS.
  • Tesseract does not require the user to "follow the instructions" to switch back to the dApp as WalletConnect does. Instead, the Wallet view is closed automatically once the transaction is signed and the user is returned back to the dApp. Hence, Tesseract requires less education and understanding from the user and is more intuitive.
  • Tesseract will never take the user to a wallet that doesn't support their network or even the network version.
  1. Connection
  • Tesseract doesn't need internet and can work locally
  1. Decentralization
  • Tesseract doesn't need wallets to register to appear on the lists. Instead, any wallet that supports Tesseract will be available for the user once installed.
  • Tesseract doesn't use the internet or servers and passes data to and from the Wallet directly using local IPC, which is more secure and is truly in the decentralization spirit.

The above is not a comprehensive list of differences but rather is what the end-user may experience right away.

The differences become even more apparent once we start talking about the technological differences. The main one is the approach chosen - WalletConnect uses the internet connection as its main data transfer mechanism, plus some additional ones for connection initiation or app switching. Tesseract is built with a totally different approach - each use case is unique and requires a different connection technology. For example, a dApp and a Wallet on the same phone are best to connect locally through IPC, while a dApp on a laptop would benefit the best from a Bluetooth connection to the Wallet on the phone. WalletConnect, however, chooses to use the Internet for both scenarios.

Tesseract encapsulates all these complexities with various connection types under the hood, thus allowing the dApps and Wallets to benefit from the best available data transport while not having to implement each one separately. For now, we have managed to implement Tesseract core architecture and local data transports for mobile, allowing the mobile native dApps to interact with the wallets the best way we know, but the more data transports (Bluetooth, NFC, etc.) we implement, the more radical differences we will see in these two approaches.

Copy link
Contributor

@keeganquigley keeganquigley left a comment

Choose a reason for hiding this comment

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

Thanks for pointing out the differences @dileping and for the deep dives @CrackTheCode016 @dsm-w3f

IMO it's important to put more focus on mobile as that will be the way that most people access wallets. Since native wallets have some advantages over the cross-platform ones, and I think it's good to have competing libraries anyway, I'm willing to go ahead with it.

@dsm-w3f
Copy link
Contributor

dsm-w3f commented Aug 4, 2023

@dileping thank you for the answer. I understood that Tesseract work locally and don't need internet connection to interact between the wallet and Dapp, what is good, with the other functionalities presented. I think is a good feature set to have, so I'll go forward with this application.

Just to add an opinion, I still think that the argumentation to convince people to use Tesseract is weak and needs more effort to show in a clear way the advantages of using it and the risks/disadvantages of connecting wallets in other ways. This is more from a marketing perspective than a technical one. Anyway, from the technical perspective looks good to me.

@dileping
Copy link
Contributor Author

dileping commented Aug 4, 2023

@keeganquigley and @dsm-w3f, thanks a lot for approving our proposal and for going through all the info I sent!

As for the weak marketing - I agree, we need to improve it. For that, we may need some help. Maybe the substrate builders program you've mentioned before? If you have any suggestions, please, let me know.

@dsm-w3f
Copy link
Contributor

dsm-w3f commented Aug 7, 2023

@dileping I think SBP gives better support for creating a business than W3F grants program. I think a good time for applying to SBP is after successfully delivering a grant final milestone, but feel free to apply.

Copy link
Member

@semuelle semuelle left a comment

Choose a reason for hiding this comment

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

Thanks for the application, @dileping. I'm happy to support this project. My only recommendation would be - in line with what Diogo and Keegan already said - to get more eyes and hands on your code. Looking at your repos, it's only your team making contributions. Ideally, there would be a community of developers involved in raising and fixing issues. Otherwise, the project stands or falls with you. Given that this is your third grant, I'd be happy to make an introduction to Square One or the SBP.

@semuelle semuelle merged commit 1ef05c1 into w3f:master Aug 15, 2023
9 of 10 checks passed
@github-actions
Copy link
Contributor

Congratulations and welcome to the Web3 Foundation Grants Program! Please refer to our Milestone Delivery repository for instructions on how to submit milestones and invoices, our FAQ for frequently asked questions and the support section of our README for more ways to find answers to your questions.

Before you start, take a moment to read through our announcement guidelines for all communications related to the grant or make them known to the right person in your organisation. In particular, please don't announce the grant publicly before at least the first milestone of your project has been approved. At that point or shortly before, you can get in touch with us at [email protected] and we'll be happy to collaborate on an announcement about the work you’re doing.

Lastly, please remember to let us know in case you run into any delays or deviate from the deliverables in your application. You can either leave a comment here or directly request to amend your application via PR. We wish you luck with your project! 🚀

@semuelle
Copy link
Member

@dileping, there are no payment details in either document. Could you add those?

@dileping
Copy link
Contributor Author

@semuelle, thanks for accepting our proposal!

I agree we need to involve the community - that's the goal. This particular grant is a milestone towards getting there by making Tesseract much easier usable. As for the rest - I'll send you an e-mail now.

abhijeetbhagat pushed a commit to web3labs/Grants-Program that referenced this pull request Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed process: private finances This application is not processed on GitHub. The team wishes its funding details to remain private. ready for review The project is ready to be reviewed by the committee members.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants