Simple Encrypted Transactions
‼️ All code within this tutorial is purely educational, and it is up to the readers discretion to build their applications following industry standards, practices, and applicable regulations.
Fairblock offers various MPC schemes for fun and novel dynamic confidential computation. One MPC scheme it offers is tIBE, where the FairyRing network is used to generate public keys for encryption and their respective decryption keys, based on a specific id, otherwise referred to as a "condition." This tutorial will guide you through using a simple Bash script to encrypt and send transactions in Fairblock with execution conditions based on a specific block height. The repo can be found here.
Conditions can take the shape of anything, be it price of an asset, interest rates, etc.
By default, apps developed on FairyRing can use FairyRing block height as the specific condition at which the respective decryption key will be generated to decrypt and trigger execution for a encrypted transaction. The encrypted messages within this tutorial are referred to, for lack of better term, as a "bank msg" where one sends tokens and a memo, all of which are encrypted.
By the end, you'll understand how to:
- Send encrypted messages and token transfers using FairyRing and its inherit functionalities leveraging aspects such as
x/pep
module. More specifically:- Create and sign transactions on Fairblock
- Encrypt transactions for deferred execution
- Retrieve transaction status and results
- Extract specific information from the decrypted messages using FairyRing. This information can be useful for creating your own specific apps leveraging this small sample of confidential computation possibilities.
A quick walk through of this demo is show in the video below. Feel free to watch it and follow along with the rest of this page. Please note that this page goes through the details of the demo, check out the "Start a cApp in 5 Minutes" section if you want a shorter version.
Demo Quick Start
To run this demo, simply download this repo, and switch to this specific feature branch, feat-auction
.
git clone https://github.com/Fairblock/fairyring.git
gco feat-auction
Now, simply run:
make devnet-up
./bankMsgWithMemoAndDecryption.sh
Upon running the ./bankMsgWithMemoAndDecryption.sh
script, you will be prompted for the following basic inputs required to:
- Specify the recipient of said bank message,
- Encrypt the message with a target block height,
- Submit the encrypted transaction to the blockchain,
- Monitor the network for transaction processing, and show the decrypted result
Demo Details
The provided bash script, bankMsgWithMemoAndDecryption.sh
, does the following:
Step | Description |
---|---|
Takes User Input | Asks for a FairyRing recipient address, the amount of uFairy to transfer, the wallet account name sending funds, and a note for the transaction that acts as the message to be encrypted. |
Gets Required Info | Fetches your public key, account address, account number, and sequence number from the list of devwallets available for the demo dev net. |
Creates a Transaction | Generates an unsigned transaction with the specified details. |
Signs the Transaction | Uses the specified account's dev net credentials to sign it securely. |
Uses x/pep Module to Encrypt the Transaction | Uses the standard convention of encrypting a message. |
Submits the Encrypted Transaction | Sends it to the local devnet. |
Waits for Confirmation | Watches the local FairyRing devnet blockchain height and checks when your transaction is included. |
Lists Decrypted Transactions | Once confirmed, it retrieves and displays the decrypted transaction. |
Through using the FairyRing network, the following perks for said transaction are achieved:
- Transaction details private using encryption.
- Ensures proper signing so transactions are valid.
- The script making it easy to interact with the FairyRing blockchain while keeping your transactions private!
Frequently Used CLI Commands
The output decrypted data is in JSON format. Developers are encouraged to parse the encrypted message for whatever data they may need for their own app design. This is where the true creative freedom comes into play!
The following are CLI commands one can use within their own scripts to work with encrypted transactions at a rudimental level, including extracting information as needed. Expand the toggle to see its details.
There are numerous ways to work with JSON files, we simply use jq
within the following CLI commands shown and our demo script within this repo. See the official jq
download docs here.
Commonly Used CLI Commands Shown in This Tutorial
Fetch the Public Key for Encryption
- Use this in your app if you need to encrypt messages or transactions.
fairyringd query pep show-active-pub-key -o json | jq -r '.active_pubkey.public_key'