Giter VIP home page Giter VIP logo

ibm / secure-bitcoin-wallet Goto Github PK

View Code? Open in Web Editor NEW
25.0 11.0 45.0 1.44 MB

Secure Bitcoin Wallet is a Dockerized version of Electrum Bitcoin Client with a Web frontend. The Electrum Bitcoin Client, a modified version of Electrum, runs as a JSON RPC server to maintain a bitcoin wallet by interacting with the bitcoin network. It can encrypt/decrypt a wallet file using an EP11 crypto server (zHSM) to protect the encryption key. The Electrum frontend, a modified version of Electrum for Laravel 5.4+, runs as a Web frontend to interact with bitcoin users via a Web browser. It runs on Laravel, an emerging application framework written in PHP taking advatnage of NodeJS for client-side rendering. These two components are Dockerized to run in a Docker container on x86 or in a Hyper Protect Virtual Server.

License: Apache License 2.0

Shell 17.06% Python 73.83% Dockerfile 8.16% PHP 0.95%

secure-bitcoin-wallet's Introduction

Bitcoin Digital Wallet

In this code pattern, we will deploy a Digital Wallet application in the public cloud. As digital wallets are targeted by hackers, it is important that the digital assets be protected in an environment that is also easily accessible by the user - also known as a "hot wallet". This includes having an environment where neither privileged admins nor external threats can compromise the data, via encryption and other mechanisms.

The Digital Wallet application consists of an Electrum Bitcoin Client backend and a Web frontend. The backend, a modified version of Electrum, runs as a JSON RPC server to maintain a bitcoin wallet by interacting with the bitcoin network. The frontend, a modified version of Electrum for Laravel 5.4+, runs as a Web frontend on Laravel to interact with bitcoin users via a Web browser. Laravel hosts an application written in PHP using Node.js for the rendering on the client (browser).

These two components are configured to run in a single IBM Hyper Protect Virtual Server, as illustrated in the following diagram. It can optionally encrypt/decrypt a wallet file using IBM Cloud Hyper Protect Crypto Services (zHSM) to protect the encryption key.

blockdiagram

When you have completed this code pattern, you will understand how to:

  • Build and run an Electrum Bitcoin Digital Wallet application
  • Stand up an IBM Cloud Hyper Protect Virtual Server
  • (Optional) Integrate with IBM Cloud Hyper Protect Crypto Services to encrypt the wallet

Steps

The frontend and backend applications can both be run locally, or on a Linux VM in the IBM Cloud, for example an IBM Cloud Hyper Protect Virtual Server.

HPVS_find

HPVS_create

Create your IBM Cloud Hyper Protect Virtual Server Instance

You can find the instructions here.

Make sure to copy and paste in your SSH public key. If you don't have one already, please follow the guide here.

Log into your Virtual Server

You can find the instructions here.

How to build the Wallet application

Start by installing Git and Docker. You typically need a root privilege. If you login as a root, typically you find # as a command line prompt. You can run the following two commands to install Git and Docker.

# apt-get update
# apt-get install -y git docker.io

If you login as a regular user, typically you need to use sudo command to install them.

$ sudo apt-get update
$ sudo apt-get install -y git docker.io

To build the application, clone the master branch from this repo and build a container out of it. If you just installed Docker in the VM, and if you want to build a container as a regular user, typically you need to add your userid to the docker group.

The build process uses a personal access token for github.com to avoid a build failure due to its access rate limit. Refer to an instruction to create one. Store your access token into ACCESS_TOKEN environment variable.

$ git clone https://github.com/IBM/secure-bitcoin-wallet.git
$ cd secure-bitcoin-wallet
$ docker build --build-arg ACCESS_TOKEN=${ACCESS_TOKEN} -t secure-bitcoin-wallet .

By default, the Dockerfile installs grpc python packages, such as grpcio-tools, to access IBM Cloud Hyper Protect Crypto Services (HPCS). Since this step can take some time and resources (e.g. memory), you can skip it by adding NO_GRPC_BUILD=1 as a build argument. This option allows you to build a container on a small VM, such as a free instance of HPVS, if you are not planning to use HPCS.

$ docker build --build-arg NO_GRPC_BUILD=1 --build-arg ACCESS_TOKEN=${ACCESS_TOKEN} -t secure-bitcoin-wallet .

How to run the application

The following sequence of commands starts a wallet container for the Bitcoin testnet, where bitcoins don't have an actual monetary value. If you run multiple wallet instances on the same VM, the WALLET_NAME and PORT should be unique among wallets in the VM. The container uses a Docker volume of WALLET_NAME to store a wallet file.

$ WALLET_NAME=<wallet-name> (e.g. alice)
$ PORT=<external-https-port>
$ docker run -d -v ${WALLET_NAME}:/data -p ${PORT}:443 --name ${WALLET_NAME}-wallet secure-bitcoin-wallet

Alternatively, you can use the following shell script in the scripts directory. Docker selects an unused port as a default, except for a few predefined wallet names (e.g. charlie for 4431, devil for 4432, eddy for 4433). The script prints the port number assgined to the wallet if a container is created successfully.

$ ./scripts/run-wallet.sh ${WALLET_NAME}
a wallet is running in container ${WALLET_NAME}-wallet at port xxxxx

How to encrypt the wallet with HPCS (optional)

Optionally, you can use an HPCS instance to encrypt/decrypt a wallet. To use an HPCS on IBM Cloud, you need to supply the following four parameters.

  • ZHSM: the domain name and the port number of the HPCS instance (e.g. ep11.{location}.hs-crypto.cloud.ibm.com:1234)
  • APIKEY: the api key for the HPCS instance (e.g. xxxxxxx-xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
  • IAM_ENDPOINT: the URL of an IAM endpoint (this is optional. a default value, https://iam.cloud.ibm.com, is used if not specified)

If ZHSM is not defined, a default software AES is used. If ZHSM is defined but APIKEY is not, we assume the HPCS instance doesn't require authentication (typical for an on-prem instance).

$ docker run -d -v ${WALLET_NAME}:/data -p ${PORT}:443 -e ZHSM=${ZHSM} -e APIKEY=${APIKEY} --name ${WALLET_NAME}-wallet secure-bitcoin-wallet

Use a Web browser to access the electrum wallet.

  • Access https://hostname:port/electrum from a browser with the port number specified for the container.
  • Accept a warning on a browser to use a self-signed certificate.
  • Click "register" to register name, e-mail address, and password, for the first time. Or click "login" if already registered.
  • Access https://hostname:port/electrum again if not redirected automatically.
  • Create and load a wallet from a Wallet tab. Leave the seed field empty unless you want to use a seed from a previously created wallet. You can set a wallet password here. Note that it is different from the login password.
  • Reload the browser.
  • Select one of five tabs (History, Requests, Receive, Send, or Sign) to interact with the wallet.

Here is a sample screenshot of the wallet to send bitcoins to a recipient.

A screenshot

WARNING: This software is for demonstration purposes only. Use at your own risk.

Additional note

  1. Persistent data

A wallet file is stored in a Docker volume, which can be examined by the following command, as the volume name is ${WALLET_NAME} when a wallet container is created as described above.

$ docker volume inspect ${WALLET_NAME}
  1. Reloading an existing wallet

To load a previously created wallet with a password in a docker volume, run the following command to create a wallet container. Replace [wallet-password] with your wallet password.

$ docker run -d -v ${WALLET_NAME}:/data -e WALLET=/data/electrum/testnet/wallets/default_wallet -e PASSWORD=[wallet-password] -p ${PORT}:443 --name ${WALLET_NAME}-wallet secure-bitcoin-wallet

License

Apache 2.0

Contributor License Agreement (CLA)

To contribute to the secure-bitcoin-wallet project, it is required to sign the individual CLA form if you're contributing as an individual, or corporate CLA form if you're contributing as part of your job.

You are only required to do this once at on-line with cla-assistant when a PR is created, and then you are free to contribute to the secure-bitcoin-wallet project.

secure-bitcoin-wallet's People

Contributors

cgallagher-129 avatar jinvanstee avatar kant avatar moriohara avatar silliman avatar stevemart avatar tnakaike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

secure-bitcoin-wallet's Issues

node:16-buster-slim image no longer available in s390x architecture, which breaks the Docker build on s390x

It appears that the image with tag node:16-buster-slim no longer supports the s390x architecture. My secure build of this repo failed because of this.

I forked the repo and changed line 16 of the Dockerfile to use the "bullseye" image instead of the "buster" image. That is, I changed line 16 to say

FROM node:16-bullseye-slim AS node

and this allowed the secure build to work.

I normally would have created a pull request for this change instead of writing an issue, but I noticed something in the build that probably warrants investigation, and, although it may be independent of the change in images, I can't be sure-

the build of the grpcio-tools wheel fails in this build.

I was able to successfully run the image I built and test its functionality (sending and receiving bitcoin on the testnet) using software crypto. I suspect that since the interface to an HSM (e.g., through Hyper Protect Crypto Services in IBM Cloud or through a GREP11 Server in Hyper Protect VIrtual Servers on-premises) uses gRPC, that it's possible that the failure of grpcio-tools to build might break the ability to use an HSM.

Since I can't rule out the possibility that the breakage of grpcio-tools is directly related to the image I'm using, I'm not creating a pull request, so that the above situation can be investigated more.

This is a snippet of output from the build that shows the failure to build grpcio-tools

INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   during RTL pass: final
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   third_party/protobuf/src/google/protobuf/generated_message_tctable_lite.cc: In static member function static const char* google::protobuf::internal::TcParser::MiniParse(google::protobuf::MessageLite*, const char*, google::protobuf::internal::ParseContext*, const google::protobuf::internal::TcParseTableBase*, uint64_t, google::protobuf::internal::TcFieldData):
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   third_party/protobuf/src/google/protobuf/generated_message_tctable_lite.cc:342:1: internal compiler error: output_operand: invalid %-code
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:    }
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:    ^
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   Please submit a full bug report,
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   with preprocessed source if appropriate.
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   error: command '/usr/bin/gcc' failed with exit code 1
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   ----------------------------------------
INFO:__main__:2022-10-22 16:50:53,138  run                      INFO    run:   ERROR: Failed building wheel for grpcio-tools

Hope I didnt break anything

Hi,

Very nice to see my old code (https://github.com/AraneaDev/laravel-electrum) is being put to good use. Unfortunately I assumed nobody was using it so after just updating it for a client to work with newer Electrum I just deleted a bunch of the older versions.

I hope that has no impact for this project, it looks like you modified it too so I assume not. If it does however please let me know which version you were depending on and I can just rerelease it from tag.

Sorry if I caused any inconvenience.
@AraneaDev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.