Skip to content

Architecture

BradGao edited this page May 21, 2021 · 1 revision

Core Wallet Architecture

As a multi-chain wallet, MaskWalletCore is designed to support multiple elliptic curves, hashing, address derivation and transaction signing methods.

The two main components of MaskWalletCore are StoredKey and Account:

  • StoredKey is named as it is created with secure "key" data. The "key" data could be a private key or a mnemonic phrases string.

    StoredKey "stored" the "key" data as the origin of other information, applications could use any Account requests to create Account structs.

  • Account contains the blockchain-specific address with several metadata. A StoredKey preserves a list of Account s.

Structs Definition

StoredKey

Name type Description
r#type StoredKeyType Indicate the creation type of this StoredKey. Either PrivateKey or Mnemonic
id String UUID generated when the StoredKey created.
hash String Hex encoded string, calculated using the double-sha256 hash.
version String StoredKey definition version. Currently "0.1.0"
payload EncryptionParams Encrypted secure data, required to be decrypted with a password to execute "mutating" methods
accounts Vec List of derived accounts

Account

Name Type Description
address String Blockchain-specific address of the account
name String Alias name set by users
coin Coin The blockchain for which this account is derived
derivation_path DevirationPath The derivation path used to derived this account. Would be an empty string for an account generated by the imported private key.
extended_public_key String Not used on Ethereum. Always be an empty string for now

Multiple Blockchain Support

MaskWalletCore defines the Entry trait, all blockchain implementations must implement it and provide their other information following the New-Chain-Integration-Checklist

Trait Definition

Entry

Name Parameters Return Value Type Description
get_supported_import_types &self Vec Return the all supported import types of blockchain
get_supported_export_types &self Vec Return the all supported export types of blockchain
validate_address &self, address: &str bool Return whether the address is valid on this blockchain
derive_address &self, coin: &Coin, public_key: &PublicKey, p2pkh: &[u8], hrp: &[u8] Result<String, Error> Derive with the input parameters and return the calculated address. Return error when fails to derive
sign &self, coin: &Coin, private_key: &PrivateKey, payload: &[u8] Result<Vec, Error> Sign with the private key and encoded payload and return the signed output. Return error when fails to sign
Clone this wiki locally