The Charge Wallet 💼 (also the Charge app) is Charge's mobile app which allows users to pay for their items and to store their assets.
The Charge Wallet is based around the 🔑 Key Management System (KMS) 🔑
The KMS main responsibility is
🔒 Cryptographically secure your items in the Vault 🔒
The KeyManagement
class ensures a singleton instance of the class which uses a public factory constructor with a private regular constructor:
class KeyManagementSystem with ChangeNotifier {
...
static KeyManagementSystem _instance;
factory KeyManagementSystem() => _instance ??= KeyManagementSystem._();
KeyManagementSystem._();
...
}
This means that by calling KeyManagementSystem()
will always result in the same instance. ??=
means that KeyManagementSystem._()
is only executed when _instance
is null
and if its executed the result will be assigned to _instance
before it is returned to the caller.
The public methods are:
// generates a new instance of a KMS
void generateInitialKMS((String encryptionKey)
// encrypt decrypted data
String encrypt(String encryptionKey, String data)
// decrypts the encrypted data
String decrypt(String encryptionKey, String data)
The Vault responsibilities are:
- Generate a default Vault for first time use
- Translate between
JSON
andVault Item
objects POST
andGET
the Vault from the server
The Vault holds a List
of Vault Items defined by:
class VaultItem {
final String label;
final VaultTypes type;
final Map<String, String> meta;
VaultItem({
@required this.label,
@required this.type,
@required this.meta,
});
The meta
field is specific to the particular Vault Item
. Currently the defined Vault Items
are:
enum VaultTypes { CryptoWallet, CreditCard, ACH, Bank }
CryptWallet.meta
:{phrase: 'mnemonic'}
The public methods are:
// POST a Vault object to the server
// body: json.encode(
// {
// 'data': encryptedData,
// 'key': key,
// 'vector': iv,
// },
// ),
Future<void> postVault(String encryptedData) async
// GET Vault object(s) from server
// [
// {
// "id": "04a5bfdc-a3a4-4351-9723-a0260f6050d9",
// "object": "vault",
// "userId": "775671ff-f70d-415d-b523-f50b05139ac9",
// "data": "...WfzY=",
// "vector": "...WmdlKZsBk0KOx9MbCBn5A==",
// "encryptionKey": "...47f0abb"
// }
// ]
Future<void> getVault() async
A User is browsing a cool online merchant store, and finds something they like to buy:
Luckily, the merchant has integrated with 💸 Charge Payments 💸 So the user is confident that there is no chance of fraud. After clicking the Checkout with Charge button, the user gets a push notification to their Charge App
The user then simply selects a Payment method stored in their Vault and securely pays for their items.