Skip to main content

Overall Data Storage Design for HD Wallet Integration

1. Databaseโ€‹

  • SQLite3 is chosen.
  • Using rn (node.js for database operations).

2. Table Structure Designโ€‹

2.1 Chain Tableโ€‹

Field NameTypeExplanation
idbigIntID
namevarcharChain Name
symbolvarcharMain Coin Name
logovarcharChain Logo
active_logovarcharActive Chain Logo
supportboolWhether this chain is supported
is_delintStatus: 0 for normal, 1 for deleted

2.2 Asset Tableโ€‹

Field NameTypeExplanation
idbigIntID
chain_idbigIntChain IDS
namevarcharAsset Name
logovarcharChain Logo
active_logovarcharActive Chain Logo
contract_addrvarcharContract Address
unitintPrecision
is_delintStatus: 0 for normal, 1 for deleted

Add data when creating main coin for the wallet, and add data when searching and adding Tokens.

2.3 Wallet Tableโ€‹

Field NameTypeExplanation
idbigIntID
chain_idbigIntID
wallet_namevarcharWallet Name
device_idvarcharDevice ID
wallet_uuidvarcharWallet UUID
mnemonic_codevarcharEncrypted Mnemonic Code
passwordvarcharPassword
asset_usddecimalTotal USD Asset
asset_cnydecimalTotal CNY Asset
has_submitboolWhether submitted
is_delintStatus: 0 for normal, 1 for deleted

Add wallet only when creating the main coin. If asset_usd and asset_cny are different from the API response, update asset_usd and asset_cny.

2.4 Wallet Asset Tableโ€‹

Field NameTypeExplanation
idbigIntID
wallet_idbigIntChain ID
asset_idbigIntAsset ID
balancedecimalBalance
asset_usddecimalUSD Asset
asset_cnydecimalCNY Asset
is_delintStatus: 0 for normal, 1 for deleted

Associate wallet asset balance when creating main coin and adding tokens.

2.5 Account Table (Account is equivalent to address)โ€‹

Field NameTypeExplanation
idbigIntID
wallet_idbigIntWallet ID
indexintBip Address Index
addressvarcharAddress
pub_keyvarcharPublic Key
priv_keyvarcharEncrypted Private Key
is_delintStatus: 0 for normal, 1 for deleted

Add when creating wallet. Add index for 1-n, when needed.

2.6 Account Asset Table (Account is equivalent to address)โ€‹

Field NameTypeExplanation
idbigIntID
address_idbigIntAccount ID
asset_idbigIntAsset ID
balancedecimalBalance
asset_usddecimalUSD Asset
asset_cnydecimalCNY Asset
is_delintStatus: 0 for normal, 1 for deleted

Add when creating wallet, update otherwise.

3. Encryption Algorithmโ€‹

Symmetric encryption algorithm AES is used, with the encryption key being the combination of device ID and user-input password. Refer to the snow code repositoryโ€™s example department code for details.

4. Operationsโ€‹

4.1. On App Launchโ€‹

Initialize once on app launch, initializing supported chains and currencies into the table with default values.

4.2. Generate Accountโ€‹

Generate mnemonic -> Verify mnemonic -> If verification passes, store encoded mnemonic into mnemonic table. Generate seed from mnemonic -> Masterkey -> Bip44 protocol -> Child private key -> Public key -> Address. Store index corresponding to Bip protocol (default 0), encrypt private key, and store in account table. Request balance update into table. Check if the phone is connected to the internet, if so, continuously request balance updates.

4.3. Export Mnemonic and Private Keyโ€‹

Export mnemonic -> Query mnemonic table -> Decrypt and return encoded mnemonic to interface. Export private key -> Query account table -> Decrypt and return private key to interface.

4.4. Import Mnemonic and Private Keyโ€‹

Import mnemonic -> Verify mnemonic -> If verification passes, store encoded mnemonic into mnemonic table. Generate seed from mnemonic -> Masterkey -> Bip44 protocol -> Child private key -> Public key -> Address. Store index corresponding to Bip protocol (default 0), encrypt private key, and store in account table. Request balance update into table. Check if the phone is connected to the internet, if so, continuously request balance updates.

Import private key -> Private key -> Public key -> Address. Store index corresponding to Bip protocol (default 0), encrypt private key, and store in account table. Request balance update into table. Check if the phone is connected to the internet, if so, continuously request balance updates.

4.6. Get Balanceโ€‹

Check if the phone is connected to the internet, if so, continuously request balance updates.

4.7. Transferโ€‹

Initiate transfer -> Organize transaction data -> Retrieve private key from account table -> Sign transaction -> Update transaction into transaction table -> Broadcast transaction -> Check transaction status and update into transaction record table.

4.8. Get Transaction Recordsโ€‹

Check if the phone is connected to the internet, if so, continuously request transaction record updates.