airgap-it / airgap-coin-lib

A library that offers a unified API to prepare, sign and broadcast multiple cryptocurrencies.
https://airgap-it.github.io/airgap-coin-lib/
MIT License
143 stars 38 forks source link

Binance Smart Chain support #29

Closed LouizFC closed 2 years ago

LouizFC commented 2 years ago

Greetings.

This issue is related to https://github.com/airgap-it/airgap-wallet/issues/55.

As the title suggests, I would like to implement BSC support into AirGap. As per https://github.com/airgap-it/airgap-coin-lib/issues/7, AirGap as a project prefers not to accumulate features that the maintainers cannot properly maintain, so I understand that my changes could end up not merged, which is fair considering the security centric approach of this project.

As per "Contribute Guidelines", I would like to know if there is interest in such a PR before implementing it?

AndreasGassmann commented 2 years ago

Hi. Thanks for reaching out and reading our guidelines.

Because BSC is very similar to ETH, I'm not expecting there to be a lot of code changes, so maintaining that code shouldn't be too much effort. My main concern is regarding the node. Are there "official" nodes that we could use?

We decided that in the long term, we will add something like "community maintained protocols" to AirGap. Those will be hidden between a flag so users need to accept a disclaimer of sorts that will explain that those protocols might break at any moment and are not maintained by us. This feature is not ready yet though. The main focus there will be to implement some kind of "sandbox" so those community protocols can't mess with the private key, for example.

I can't give you any promises, but out of all possible chains, I think BSC might be the one we would most likely merge :).

LouizFC commented 2 years ago

My main concern is regarding the node. Are there "official" nodes that we could use?

I am a Integration Engineer, but I will admit that I am a bit of a newbie to the crypto world, so could you please clarify? as Node, you mean an official entrypoint where we broadcast/query the transactions? There are some words that I am not yet familiar with.

AndreasGassmann commented 2 years ago

The node is the backend service that holds the data of the blockchain and is continuously connected to other nodes to always have the latest state of the network. It is used to broadcast transactions and for some simple queries (eg. balance of an address).

The API of the node is quite limited, which is why there is often something called an "indexer", which stores the blockchain data in a database and makes more advanced queries easier (eg. getting all transactions of an address).

Both of those services are needed in AirGap. The problem is that if the node / indexer goes down, the protocol will stop working (eg. no balances or transaction can be shown, no transactions can be broadcast). So the best solution is to host that node ourselves, which is quite a bit of work, depending on the chain.

Here is the example for Ethereum: https://github.com/airgap-it/airgap-coin-lib/blob/master/packages/core/src/protocols/ethereum/EthereumProtocolOptions.ts#L15-L18

LouizFC commented 2 years ago

I see, thank you for clarifying. That said I will study these concepts. I took a look at the BSC docs and, selfhosted nodes aside, I found the information needed. I start working on the implementation probably in the weekend.

AndreasGassmann commented 2 years ago

Let us know if you hit any issues. I'm assuming you can extend the EthereumProtocol and create a new BinanceSmartChainProtocol with it. In the best case, you actually only need to provide the new node URLs and chain ID, the rest should be largely the same.

AndreasGassmann commented 2 years ago

I'm happy to announce that AirGap Vault is now compatible with MetaMask. See our tutorial here. Using this approach, it is possible to use BSC with AirGap Vault.

Adding BSC to AirGap directly is still an option, but in my opinion it's now not as urgent anymore as before because there is an alternative.

LouizFC commented 2 years ago

I used the MetaMask integration recently at it works perfectly.

I am closing this because I think there is no tangible benefit for implementing this natively. BSC documentation at the moment is not really friendly, and setting up self hosted nodes is poorly documented (again, at this moment).