-
@ Beme
2023-08-19 13:20:33I am one of the many victims of the BlockFi bankruptcy, a flow on effect from the FTX crash. Yes, laugh as you will! “Not your keys, not your Bitcoin”. I’ve always known this, but I was too complacent and lazy to move it out.
One reason was that I could never find a wallet I really liked, and that I could feel I could trust. So I decided to build my own: Beme. Once finished, this wallet will be open-sourced. The things I am trying to achieve with my wallet are things that I felt no other mobile wallet really got right:
-
Ability to make multiple wallets in the single app, including single-key Bitcoin, multi-sig Bitcoin, and lightning
-
Ability to send funds between my own wallets without having to copy QR codes or BTC addresses
-
Ability to send funds to other wallets without having to copy QR codes or BTC addresses
-
Ability to message users I have sent funds to
-
Ability to track the BTC price and the value of my wallet
-
Ability to track my transactions, attach descriptions and download a CSV of all transactions
-
Ability to create a non-custodial lightning wallet without having to run a node
I’ve explored countless wallets, some of which achieve some of the above but none that get close to all. In my experience, some outstanding wallets include Blue wallet, Wallet of Satoshi, Samourai wallet and Mutiny. Before I get into my DevX experiences, I need to give a particular shoutout the open-sourced Blue Wallet, without which I would never had made such progress.
Beme Architecture
Beme wallet architecture: Beme is a bitcoin/lightning wallet that allows users to create multiple wallets. It is powed via nostr to allow simple P2P payments and messages.
The wallet does not require any KYC or any user information. Beme allows you to create three types of wallets: Beme Bitcoin wallet, Beme multi-sig wallet, and Lightning Beme wallet. You can only create one lightning wallet and as many Bitcoin wallets as you need. The Bitcoin wallet is created and stored on the phone. The wallet is encrypted and stored using react-native-async-storage. Accessing the wallet data requires biometrics to unlock the wallet and access the seed-phrase.
The lightning and Beme Bitcoin wallets can be connected to Nostr to enable easy P2P payments. To keep the Beme multi-sig wallet more secure, this wallet does not allow connection via Nostr to other users.
The Beme API is used to control the lightning wallet, improve the speed of Nostr queries, and to collect basic de-identified usage information.
Technologies
To create Beme, I have explored the following technologies:
-
Cloud: AWS & Google cloud
-
Messaging: Nostr & cloud API
-
Mobile: React-native & expo
-
React Libraries:
- Bitcoin: BitcoinJs Lib
- Lightning: LN-Zap, LND, LNDHub (blue wallet), Greenlight (Blockstream), blixt
From a DevX point of view, the best technology to use has been Nostr. It is truly plug-and-play and extremely powerful. Its ease of use has enabled rapid development around the communications side of the app. Prior to Nostr, I explored doing something similar on google cloud, but Nostr worked out of the box and achieved all that I needed.
I had already used BitcoinJs in a previous react web-app project so I naturally chose it for this project. However, it was far more challenging with react-native compared to web. My first version of the app was created using expo which is not supported by BitcoinJS. So I re-wrote the app in plain react-native to get it working. A further challenge has been navigating library versions that work properly together. The biggest challenges have been: - react-native: currently v0.71.8 - react-native-reanimated: currently v3.0.0 - react-native-crypto: currently v2.1.0 - tiny-secp256k1: currently v1.1.6
I attempted to use react-native turbo modules which required upgrading react-native-reanimated, react-native and various other libs. However, I could not get it to work properly with react-native-crypto and tiny-secp256k1. I attempted to get it working by applying a patch package to various libs within tiny-secp256k1 — but in the end I was patching so much that it felt easier to write a whole new package. I have not ended up upgrading.
The most difficult technology to use, by far, has been lightning. From a devX point of view, this has been the most painful. This is partly the reason I explored so many options. If you are going to work with lightning, I can recommend you do not waste time with the following:
-
LN-Zap: the library was out-dated compared to LND and I could not get it to work properly on testnet.
-
blixt: This was very complicated and, while I could get it to run, it was buggy and difficult to debug.
Greenlight has the potential to be extremely powerful, but it is still very early. I have joined their testing platform which works well in python, but their JS implementation does not yet work. If you attempt Greenlight, I recommend using their rust/python framework.
I ended up going with LND (lightning labs) combined with LNDHub to communicate with the wallet. LND was challenging to set up and to understand what was really going on under the hood. I also think it is overly bloated for what I am trying to do.
LNDHub was relatively easy to set up and makes communication to the LND node much simpler. I highly recommend coupling an LND node with LNDHub.
Cloud
Beme allows you to create a lightning wallet in the cloud. The current implementation uses Google cloud for the API and AWS for hosting the lightning nodes. Breaking it up between two cloud providers has been mainly driven by cost; Google cloud is free for a small number of monthly active users, and AWS provides free t2.micro instances for 1 year. Eventually, the idea will be to consolidate to a single cloud provider.
Communications between the wallet and the cloud is facilitated via the Beme API. This architecture means the lightning wallet only needs a single IP address open (the API server), providing a far more secure system. Each lightning wallet is run in a docker container on AWS. The API facilitates the creation of a wallet and the communications to control the wallet. Users can retrieve their keys at any time and optionally choose to run their wallet themselves.
Tradeoffs
There are a few tradeoffs from using Beme that users should be aware of:
-
A mobile wallet will always be less secure than a hardware wallet. The tradeoff here is between UX and security. I would not recommend users to keep their life-savings on Beme. Instead consider using a hardware wallet for large amounts and Beme to simplify the use of regular payments.
-
The lightning implementation on the cloud is costly to run. In order to provide the lightning wallets to users for free, all lightning wallets created through Beme are routed through the Beme lightning node. This means that Beme can always collect a routing fee which offsets the cloud costs.
-
Nostr is a powerful protocol. The advantage of using it is that users own their data and they can always access it by deriving it from their seed-phrase. The downside is that it is still a slow protocol compared to a cloud API, and is sometimes inconsistent with the messages it retrieves. I’ve run experiments where every now and again, messages are dropped for an unknown reason. Nostr has also made it difficult to optimise the app for speed. I’ve had to store a lot more data locally rather than fetch it as required due to its slow speed.
And thats it! I hope you have found this exploration of technologies useful. I hope you find the wallet useful once it is released.
Bitcoin Beme
Liked this article? help support more bitcoin: bc1q880n3vjzqa054xr6hwcx7756873z47kcqr052s ln-url: ourbean71@walletofsatoshi.com
-