Your Secrets are Safe with Me

Building a secret messaging application on Oasis

Vishwanath Raman
Oasis Labs
Published in
8 min readMay 15, 2019

--

Secret messaging as a service

In order to highlight some of the new features of the Oasis Dashboard — the ability to deploy and track usage of confidential smart contracts — this blog post outlines how developers like you can build and deploy a simple confidential messaging application on our dashboard.

Messaging apps are ubiquitous with consumer and business applications alike. Messaging apps make up 7 of the top 20 apps on the Apple App Store and 6 of the top 20 apps in Google Play; messaging is integrated in business applications like Slack, e-commerce platforms like Intercom, and more. Yet what most of these messaging apps fail to ensure is a promise of privacy and ownership for every user of the application.

Enter Oasis, which seeks to combine the decentralization of blockchain and the privacy and confidentiality guarantees of secure computing technology. Combining the two gives users an opportunity to build and use messaging applications where control of data in the app remains in the hands of the user and messages are by design private — even from the app developer or Oasis.

Why messaging as a service?

Similar to software as a service, messaging as a service provides a clean separation of concerns. We want to give developers the ability to use this service either for standalone messaging applications or for integrating it within richer applications, such as games, to provide bulletin boards or facilitate in-app communication for all participants. Since the contract supporting this service is open-source, developers can clone and enhance the contract in ways that appeal to their customers.

Why secret messaging?

Consider requirements from face-to-face communication. As a user, there are some messages that I simply don’t want in the hands of anyone other than my intended recipients. That includes simple messages to family members, to our communication with service providers like doctors, auditors, investment advisors, due-diligence partners, or even friends in an online game. A broadcast message is like pasting a yellow sticky note on a public bulletin board — anyone who wants to, can find it and access it. A directed message, on the other hand, is private communication that no one, including the provider of the service should have access to. This is a natural segue into the next question, Why Oasis?

Why Oasis?

Oasis is a privacy-first cloud computing platform that provides not only integrity, as other blockchain platforms do, but also confidentiality in compute and storage, and privacy in the application layer. A contract running on Oasis is akin to a group of functions, with state, like traditional serverless cloud technologies, but with integrity, confidentiality, and privacy bolted in. The confidentiality starts with signed transactions, and journeys through hardware-based secure enclaves, to encrypted, auditable storage on the blockchain.

The confidentiality and secure computing technologies are requisite to building a truly secret messaging service — ensuring private messages are always encrypted, both in transit and in storage, and are never decrypted outside of secure enclaves giving us an unprecedented level of secrecy.

How to build a secret messaging contract

To build the secret messaging smart contract, I’ve used Rust. For a tutorial on how to build Rust smart contracts on Oasis check out Developing Rust Smart Contracts. Here are high-level requirements for the contract:

Identify users

  • Support wallet address based identification

A user can broadcast a message up to a fixed maximum length

  • All users get to see broadcast messages
  • Support retrieving the last k broadcast messages

A user can send a message up to a fixed maximum length to another user

  • They are considered friends after the first message is sent
  • The message sent is seen only by the intended recipient as part of her interaction with the sender and in sequence
  • The sender sees all of his exchanges with the recipient in sequence
  • Support retrieving the last k messages exchanged

Support searching over friends

  • A user can see all of her friends

I will walk through some of the aspects of supporting this functionality that provides a glimpse of service internals. The method send is used to send a directed message from one user to another. Let’s look at how we maintain the friends list in the following code fragment, redacted to focus on relevant bits. You can access the full secret messaging repository on github.

The method update_friend is reproduced here in full,

Storage requires a key to store a piece of data that becomes a part of contract state. We use the Rust tiny_keccak crate for key generation. Friends of a user are stored as a hashset. We retrieve the current set of friends, insert the new one, convert the updated set into a byte stream and stash it in storage as you can see in the above implementation. The state of the contract is stored for the life of the contract. By creating an instance of the contract without expiry, everything stored is always in storage. An enhancement to this contract will be automatic message expiry amongst other things. We invite you to enhance this contract as you like and would love to hear of interesting extensions.

Once you have the contract sources you can test it using the instructions for using contract-kit. Once you bring up contract-kit, you can use truffle to compile and test the non-confidential transactions in the test. For confidential transactions please set MNEMONIC in truffle-config.js to the mnemonic for your wallet on devnet and run the following on our devnet,

You should see this snippet in your console,

The contract is available for use on our dashboard. In the next section we will describe how you can instantiate the contract using our dashboard and use it in your application.

Using secret messaging from our dashboard

To use secret messaging as a service, you should use the Oasis Dashboard. (You can learn more about the Dashboard and how to get set up in this simple tutorial).To get started, log into the Oasis Dashboard.

To ensure a more seamless developer experience on the Oasis network, the Dashboard is designed to provide auto-funding and soft wallets. This helps avoid having to setup MetaMask or constantly update your wallet with Dev tokens any time you make a transaction (a challenging pain point of many blockchain protocols). When you log in to the Oasis Dashboard you’ll automatically be funded with up to to 1DEV per day with an automatic top-off every 24 hours. This way, you don’t have to install or use MetaMask. You get a soft-wallet when you sign in for the first time and then funding to deploy and run contracts happens automatically under the hood. This is among the steps we are taking to make it a seamless developer experience to build contracts on the Oasis network.

Once you log in, select a new project and then pick the MessageBoard contract from the list of pre-created deployable contracts. This one is what we described in the earlier section. Once you pick the MessageBoard for deployment, you will be presented with a card for deployment parameters. Fill in the instantiation arguments for the contract as shown in Figure 1, and hit Deploy. You should see your deployment in a new card with the contract address as shown in Figure 2. You are now good to use the contract address, by copying it from the card by clicking on it, in your application.

Figure 1. Filled in deployment arguments for the MessageBoard contract
Figure 2. Post deployment card with copyable contract address

Here is a snippet of code in javascript that you can use to create an instance of the deployed contract using the contract address,

You can now use instance for transactions such as,

and,

You can test the dashboard deployment using test/test-dashboard.js, in the oasis-messaging git repository, after setting MNEMONIC in truffle-config.js to the mnemonic for your wallet on devnet and running the following,

You should see,

Conclusion

We hope you enjoyed this simple tutorial. This is just one example of the type of functionality you can create and deploy on the Oasis network. We’re excited to see what you build next! Share your latest contracts with us at feedback@oasislabs.com.

Resources

Acknowledgments: Thanks to contributions from Nick, Armani, David, Will, Naheed, Anne, and Andrew.

--

--