# README
go-crypto-wallet


Wallet functionalities to create raw transaction, to sing on unsigned transaction, to send signed transaction for BTC, BCH, ETH, XRP and so on.
What kind of coin can be used?
- Bitcoin
- Bitcoin Cash
- Ethereum
- ERC-20 Token (under development)
- Ripple
Current development
- This project is under refactoring
- based on
Clean Code
,Clean Architecture
,Refactoring
- based on
- ERC-20 token is under development
- Bitcoin Core version 22.0 is released. Must be cought up.
Expected use cases
1.Deposit functionality
- Pubkey addresses are given to our users first.
- Users would want to deposit coins on our system.
- After users sent coins to their given addresses, these all amount of coins are sent to our safe addresses managed offline by cold wallet
2.Payment functionality
- Users would want to withdraw their coins to specific addresses.
- Transaction is created and sent after payment is requested by users.
3.Transfer functionality
- Internal use. Each accounts can transfer coins among internal accounts.
Wallet Type
This is explained for BTC/BCH for now.
There are mainly 3 wallets separately and these wallets are expected to be installed in each different devices.
1.Watch only wallet
- Only this wallet run online to access to BTC/BCH Nodes.
- Only pubkey address is stored. Private key is NOT stored for security reason. That's why this is called
watch only wallet
. - Major functionalities are
- creating unsigned transaction
- sending signed transaction
- monitoring transaction status.
2.Keygen wallet as cold wallet
- Key management functionalities for accounts.
- This wallet is expected to work offline.
- Major functionalities are
- generating seed for accounts
- generating keys based on
HD Wallet
- generating multisig addressed according to account setting
- exporting pubkey addresses as csv file which is imported from
Watch only wallet
- signing on unsigned transaction as first sign. However, multisig addresses could not be completed by only this wallet.
3.Sign wallet as cold wallet (Auth wallet)
- The internal authorization operators would use this wallet to sign on unsigned transaction for multisig addresses.
- Each of operators would be given own authorization account and Sing wallet apps.
- This wallet is expected to work offline.
- Major functionalities are
- generating seed for accounts for own auth account
- generating keys based on
HD Wallet
for own auth account - exporting full-pubkey addresses as csv file which is imported from
Keygen wallet
to generate multisig address - signing on unsigned transaction as second or more signs for multisig addresses.
Workflow diagram
BTC
1. Generate keys
2. Create unsigned transaction, Sign on unsigned tx, Send signed tx for non-multisig address.
3. Create unsigned transaction, Sign on unsigned tx, Send signed tx for multisig address.
Requirements
- Golang 1.16+
- golangci-lint 1.42+ (for development)
- direnv
- Docker
- MySQL 5.7
- Node Server
Installation
see Installation
Command example
Setup keys for BTC
Keygen wallet
# create seed
keygen create seed
# create hdkey for client, deposit, payment account
keygen create hdkey -account client -keynum 10
keygen create hdkey -account deposit -keynum 10
keygen create hdkey -account payment -keynum 10
keygen create hdkey -account stored -keynum 10
# import generated private key into keygen wallet
keygen import privkey -account client
keygen import privkey -account deposit
keygen import privkey -account payment
keygen import privkey -account stored
Sign wallet
# create seed
sign create seed
# create hdkey for authorization
sign -wallet sign1 create hdkey
sign2 -wallet sign2 create hdkey
sign3 -wallet sign3 create hdkey
sign4 -wallet sign4 create hdkey
sign5 -wallet sign5 create hdkey
# import generated private key into sign wallet
sign -wallet sign1 import privkey
sign2 -wallet sign2 import privkey
sign3 -wallet sign3 import privkey
sign4 -wallet sign4 import privkey
sign5 -wallet sign5 import privkey
# export full-pubkey as csv file
sign -wallet sign1 export fullpubkey
sign2 -wallet sign2 export fullpubkey
sign3 -wallet sign3 export fullpubkey
sign4 -wallet sign4 export fullpubkey
sign5 -wallet sign5 export fullpubkey
Keygen wallet
# import full-pubkey
keygen import fullpubkey -file auth1-fullpubkey-file
keygen import fullpubkey -file auth2-fullpubkey-file
keygen import fullpubkey -file auth3-fullpubkey-file
keygen import fullpubkey -file auth4-fullpubkey-file
keygen import fullpubkey -file auth5-fullpubkey-file
# create multisig address
keygen create multisig -account deposit
keygen create multisig -account payment
keygen create multisig -account stored
# export address
keygen export address -account client
keygen export address -account deposit
keygen export address -account payment
keygen export address -account stored
Watch wallet
# import addresses generated by keygen wallet
watch import address -account client -file client-address-file
watch import address -account deposit -file deposit-address-file
watch import address -account payment -file payment-address-file
watch import address -account stored -file stored-address-file
Operation for deposit action
# check client addresses if it receives coin
watch create deposit
# sign on keygen wallet
keygen sign -file xxx.file
# send signed tx
watch send -file xxx.csv
Operation for payment action
# check payment_request if there are requests
wallet create payment
# sign on keygen wallet for first sigunature
keygen sign -file xxx.file
# sign on sign wallet for second sigunature
sign sign -file xxx.file
# send signed tx
watch send -file xxx.csv
TODO
Basics
- Various monitoring patterns to detect suspicious operations.
- High coverage of UnitTest.
- Add CircleCI or other CI service
- Add new coins like Ethereum.
For BTC/BCH
- Change ORM to sqlboiler
- Implement proper database transaction.
- Re-design procedure for creating Multisig address.
- Flexible multisig proportion M:N. For now only 2:2 fixed proportion is available.
- Add bech32/segwit address
- Tweak for another coin like BCH
- Tweak key generation logic for multisig address for BCH.
- Implement
encryptwallet
to keygen/sign wallets - Lock/Unlock wallet for security reason, authorized operator is available.
- Backup/Restore for wallet.dat. If wallt.dat is broken, it's not easy to recover.
- Refactoring logic for unsigned transaction creation.
- Multisig-address is used only once because of security reason, so after tx is sent, related receiver addresses should be updated by is_allocated=true.
- Sent tx is not proceeded in bitcoin network if fee is not enough comparatively. So re-sending tx functionality is required adding more fee.
For ERC20 token
- Add sample ERC20 token for development. ERC20 Token
- Add any useful APIs using contract equivalent to ETH APIs
For ETH
- Add any useful APIs
- Generating key by HD Wallet
- Importing private key
- Exporting addresses to watch wallet
- Importing exported address in watch wallet
- Creating unsigned raw transaction for deposit
- Creating unsigned raw transaction for payment
- Creating unsigned raw transaction for transfer
- Signing on unsigned raw transaction
- Sending signed transaction
- Transaction monitoring
- Make sure that
quantity-tag
is used properly. e.g. when getting balance, which quantity-tag should be used, latest or pending. - For now it works on Go Ethereum. Adapting to Ganache
- How to manage password for private key. Password would be passed from command line argument.
For XRP
- APIs to call Admin rippled Methods
- APIs to call Public rippled Methods
- Build Rippled Server
- Build gRPC Server as RippleAPI Server. Repository is here
- gRPC Client to call RippleAPI
- Generating Keys
- Exporting addresses to watch wallet
- Importing exported address in watch wallet
- Creating unsigned raw transaction for deposit
- Creating unsigned raw transaction for payment
- Creating unsigned raw transaction for transfer
- Signing on unsigned raw transaction
- Sending signed transaction
- Transaction monitoring
- How to manage secret for private key. Password would be passed from command line argument.
Project layout patterns
- The
pkg
layout pattern, refer to the linked URLs for details.