You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: confidential-computing-layer/ibc/usecases/confidential-voting.md
+145-24
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,17 @@ description: >-
8
8
9
9
## Overview <ahref="#overview"id="overview"></a>
10
10
11
-
This tutorial explains how to upload a confidential voting contract on Secret Network, which you can execute and query for private voting on any IBC-connected chain. 🚀 In this example, **you will learn how to deploy a confidential voting contract on Secret Network which you will execute from Osmosis mainnet**. 
11
+
This tutorial explains how to upload a confidential voting contract on Secret Network, which you can execute and query for private voting on any IBC-connected chain. 🚀 
12
+
13
+
{% hint style="info" %}
14
+
In this example, **you will learn how to deploy a confidential voting contract on Secret Network which you will execute from Osmosis mainnet**. 
15
+
{% endhint %}
16
+
17
+
**The SDK abstracts IBC interactions with the Secret Network for applications that use Cosmos wallets**. It introduces a secure method for generating confidential messages and reliably authenticating users at the same time using the `chacha20poly1305` algorithm.
18
+
19
+
{% hint style="info" %}
20
+
View the typescript SDK [here](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/tree/main/next-frontend/src/ccl-sdk), which we will learn how to implement shortly :tada:
21
+
{% endhint %}
12
22
13
23
In this tutorial you will learn: 
14
24
@@ -158,7 +168,7 @@ The `Extension` variant in`ExecuteMsg` leverages the functionality of `handle_en
@@ -168,7 +178,7 @@ Now that you understand how the encryption SDK functions, let's look how it's co
168
178
}
169
179
```
170
180
171
-
[Vote on Proposal](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/next-frontend/src/functions/Gateway.ts#L71): 
181
+
[**Vote on Proposal**](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/next-frontend/src/functions/Gateway.ts#L71)**:** 
@@ -178,7 +188,7 @@ Now that you understand how the encryption SDK functions, let's look how it's co
178
188
}
179
189
```
180
190
181
-
Both of these functions access a confidential voting `contract`we have previously deployed on Secret Network contract. 
191
+
Both of these functions access a confidential voting `contract`already deployed on Secret Network (at the end of this tutorial, you will learn how to deploy your own). 
182
192
183
193
Then, we call the `execute_gateway_contract` function, which is where all of the cross-chain SDK logic is implemented using IBC hooks: 
184
194
@@ -209,7 +219,27 @@ You can further examine `sendIBCToken` and `gatewayChachaHookMemo` in the CCL-SD
209
219
210
220
### **Query Messages**
211
221
212
-
To query encrypted votes using the CCL SDK, use the `enum` called [`InnerQueries`](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/deploy-scripts/contracts/secret-voting/src/msg.rs#L35), which wraps the possible queries in the voting smart contract, namely, `MyVote`, with the CCL SDK encryption logic:
222
+
There are two types of queries using the CCL SDK: 
223
+
224
+
1.**Unauthenticated queries** ie `Extension`, which are queries that don’t require sensitive or protected data. Example: Retrieving a list of proposals or votes, which is public.
225
+
2.**Authenticated queries** ie `Inner Queries` (`WithPermit`, `WithAuthData`), which are queries that require `auth_data` from the caller for permission validation. Example: `MyVote { proposal_id }` retrieves a user-specific vote.
226
+
227
+
||**Extended Queries**|**Inner Queries**|
228
+
| - | -------------------- | ----------------- |
229
+
230
+
|**Data Access Level**| Public or general data | Private or user-specific data |
To query encrypted votes using the CCL SDK, use the `enum`[`InnerQueries`](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/deploy-scripts/contracts/secret-voting/src/msg.rs#L35), which wraps the possible queries in the voting smart contract, namely, `MyVote`, with the CCL SDK encryption logic:
`InnerMethods` leverage the SDK by using the [`GatewayQueryMsg`](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/deploy-scripts/packages/sdk/src/gateway.rs#L33) types to structure to query encrypted query cross-chain votes:
260
+
`InnerMethods` leverages the SDK by using the [`GatewayQueryMsg`](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/deploy-scripts/packages/sdk/src/gateway.rs#L33) types to query encrypted cross-chain votes. You have the choice of using two different types of encrypted queries: `query_with_auth_data` and `query_with_permit.` In this tutorial, you we will learn how to implement `query_with_permit`. 
Now let's take a look at the frontend code to see how query\_with\_permit is implemented**.**:smile:
300
+
301
+
### **Frontend Query Logic** 
302
+
303
+
The Next.js query decryption logic can be found in [Gateway.ts](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/main/next-frontend/src/functions/Gateway.ts):
Because votes are encrypted, we must decrypt them in order to query a wallet's votes. The frontend function [`query_contract_auth`](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1aa91625546547960fd9556e17f14f31d99d726f/next-frontend/src/functions/Gateway.ts#L116) securely queries the Secret smart contract using **query permits**, ensuring that only authorized users can access sensitive data. Query permits are cryptographic credentials that:
You now should have all the tools you need to use the IBC CCL toolkit! Lastly, let's learn how to deploy your own voting contract on Secret Network :clap:
365
+
254
366
## How to upload a voting contract to Secret Network
255
367
256
368
`cd` into `deploy-scripts` and install the dependencies: 
@@ -291,8 +403,17 @@ In your terminal, a `codeID`, `codeHash`, and `contractAddress` will be returned
Finally, update [config.ts](https://github.com/writersblockchain/cosmos-ccl-encrypted-payloads-demo/blob/1429ba2e713f8156f4a82a782827dd1830628865/next-frontend/src/ccl-sdk/config.ts#L68) with your contract's code\_hash and address:
Congratulations on completing this on using Secret Network's IBC SDK to encrypt votes cross-chain using Secret smart contracts! 🎉 You've explored the intricacies of encrypted messaging, cross-chain IBC interactions, and secure smart contract execution using the Secret Network CCL SDK. By building and running the fullstack application, you’ve gained hands-on experience in contract deployment, frontend integration, and secure querying with query permits. 🚀
0 commit comments