The CryptoDreams hardware wallet is a proof-of-concept prototype showcasing Android Things running on the very nice PICO-PI-IMX6UL. It uses a combination of built in java code as well as Firebase functions and real time databases to provide a custom cryptocurrency hardware wallet.
Using the supplied code and google services the wallet can receive transactions using an API. We can simulate a device-to-device transfer by using Postman and crafting an API call to our Firebase function. The function stores the transaction and the amount into a Real-Time database. The CryptoWallet has a call-back that checks if there is a new item added to the database. When it detects the new transaction record, it displays the result on the screen for the user to acknowledge.
This is what the Firebase function looks like:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.addTransaction = functions.https.onRequest((req, res) => {
const transaction = req.query.transaction;
admin.database().ref('/new-transaction').push({ transaction: transaction }).then(snapshot => {
var message = `${transaction} received`
res.status(201).send( transaction );
});
});
And we also have the call back shown here:
mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("new-transaction");
mDatabaseRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.d(TAG,"something added: " + s);
Log.d(TAG,"as a string: " + dataSnapshot.getValue().toString());
String str = dataSnapshot.getValue().toString();
//JSONObject jsonObj = new JSONObject();
// jsonObj.getJSONArray()
try {
String result = str.substring(str.indexOf("=") + 1, str.indexOf("}"));
//Change the UI
sendCommand("page 2");
sendCommand("t1.txt=\"" + result + "\"");
} catch (IOException e) {
Log.e(TAG, "Error", e);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.d(TAG,"something changed");
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.d(TAG,"something removed");
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.d(TAG,"something moved");
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG,"something broke");
}
});
The User Interface was designed in Photoshop and then programmed onto the Nextion HMI display using the Nextion GUI Editor.
Supplied code showcases the ability of the wallet to respond to various touch events. During the application initialization, various callbacks are registered to the serial interface of the screen. This allows us to capture the events and parse the incoming data. Depending on the data received, a different function is called. You can lock the screen, initiate a balance refresh, and check on current market prices for various crypto currencies.
This project is built from the UART Loopback example in the Android Things example project. It provides a great starting point for interfacing with serial devices.
Areas to Expand On
The project is just the beginning. I plan to fully develop this to support many currencies and markets. A few items that need to be worked on include true cryptographic security, a web based portal or companion app that allows you to manage the device remotely. The functions need to be polished for cleanup and archival reasons. All-In-All, I feel that the Android Things platform running on the PICO-PI would make a great overall stack for something like a crypto hardware wallet.
Comments