This doc will define our wallet's type and give a architecture guideline.
TW wallet if a POC program, we will prove that the concept of digital asset and digital identity can be integrated into a App, which would support authority management and asset management of DAPP.
The wallet try to fullfil some important requirements, including but not limited to:
- Wallet should help user register digital identity in blockchain.
- Wallet should help user manage digital asset, user would view, transfer asset in the wallet.
- Wallet should have a place to run DAPP.
- Wallet should help user get truthful claim.
- Wallet should help user show truthful claim to service provider.
According to functional requirements, wallet should consider these technology:
- Wallet can generate DID to identify user's digital identity.
- We should write a smartContract to store the relationships of DID, Address, Public Key.
- Wallet can create key pair and support HD wallet.
- Wallet can connect to blockchain to get information of account.
- Wallet can sign a transaction with private key and connect to blockchain to broadcast transaction.
- Wallet should have a webview container to run DAPP and have a bridge to communicate with DAPP. Communicate Bridge should be design to fullfil different requirements of DAPP.
- Wallet should integrate truthful claim CA, these CAs is a plugin and can be removed.
- Wallet should have ability to scan a QR Code and let use give authorization to show some necessary claim information to service provider.
- generate DID uri.
- call smart contract interface (this step can go through server) to register relationship of DID, Address, Public key
- generate 12 mnemonic words
- let user input 6 pin codes, this pin is not BIP39 Passphrase
- store pin in secure storage
- generate seed and BIP32 Root Key
- when user click add, show address of m/44'/60'/0'/0/{index} in the ui.
store mnemonic words here
pin is not BIP39 Passphrase, because we want user can restore account by mnemonic words in any eth wallet without passphrase
We can choose different algorithm to generate address and DID. In our wallet, we just connect to quorum and use ETH address. We can use Eth address and add prefix to generate DID, such as "did:tw:eth-address".
User can transfer TWP with DID, but the feature do not mean DID bind to private key of address. We should remember DID has it's own smart contract, we can define who can control DID. For example, we can add a controller to DID smart contract and change it in the future.
For make our POC easier, we combine DID and wallet account, they have same private key.
- select wallet account to transfer
- fill to-address and amount
- sign transaction with private key
as same as Import DID
We should consider some Non-functional requirement in wallet.
- We prefer KeyStore file instead of private key.
- KeyStore has password and wallet should not sore password.
- We store KeyStore file in secure storage.
- Wallet should not log password or sensitive data to file or console.
- Config file and database should be encrypted.
- Wallet should use certification pinning to avoid man in the middle attack.
- Wallet should use https to communicate with server.
- Wallet should communicate with server with encrypted data above https.
- Communicate encrypt key should be changed frequently.
- Android APK should be reinforcement.
- Can not record screen while showing mnemonic words.
we should dig into details of encrypted communication and reinforcement of APK.
Wallet should split state out of view to make our application has hierarchs. MobX is a library makes state management simple and scalable by transparently applying functional reactive programming (TFRP).
Flutter is Google's UI toolkit for building natively compiled applications for multiply targets. Wallet use Flutter as UI Framework to build Android and iOS application.
Two methods:
- get nonce from blockchain or server.
- handle by client nonce pool.
we choose 1.
We should consider requirements evolvement in the future. I list some of them here:
- Support more tokens which may different from erc20
- DID have it's own uri algorithm
- Forget DID private key
- Forget digital asset private key
- sign transaction for other apps
- show claim for other apps
- support DAPP store
- support new encrypt library