-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from NillionNetwork/feat/testnet-config
add testnet config and blind app guide for hackathon
- Loading branch information
Showing
18 changed files
with
780 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
The JavaScript Client makes use of browser web-workers. To make your app cross-origin isolated, you'll need to set COOP and COEP headers, completed for you in [the cra-nillion webpack.config.js](https://github.com/NillionNetwork/cra-nillion/blob/main/webpack.config.js) | ||
|
||
``` | ||
Cross-Origin-Embedder-Policy: require-corp | ||
Cross-Origin-Opener-Policy: same-origin | ||
``` | ||
|
||
<Tabs> | ||
|
||
<TabItem value="React" label="ReactJS" default> | ||
|
||
Add headers and create a nilchain proxy in your [webpack.config.js](https://github.com/NillionNetwork/cra-nillion/blob/main/webpack.config.js) | ||
|
||
```js | ||
module.exports = { | ||
devServer: { | ||
static: { | ||
directory: path.join(__dirname, 'public'), | ||
}, | ||
headers: { | ||
'Cross-Origin-Embedder-Policy': 'require-corp', | ||
'Cross-Origin-Opener-Policy': 'same-origin', | ||
}, | ||
hot: true, | ||
client: { | ||
overlay: false, | ||
}, | ||
historyApiFallback: true, | ||
proxy: [ | ||
{ | ||
context: ['/nilchain-proxy'], | ||
target: process.env.REACT_APP_NILLION_NILCHAIN_JSON_RPC, | ||
pathRewrite: { '^/nilchain-proxy': '' }, | ||
changeOrigin: true, | ||
secure: false, | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
For more information, check out | ||
|
||
- https://developer.chrome.com/blog/enabling-shared-array-buffer/ | ||
- https://web.dev/articles/coop-coep | ||
- https://webpack.js.org/configuration/dev-server/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
|
||
1. Create a python [virtual environment](https://docs.python.org/3/library/venv.html) | ||
|
||
``` | ||
python3 -m venv .venv | ||
``` | ||
``` | ||
python3 -m venv .venv | ||
``` | ||
|
||
2. Activate the python virtual environment | ||
|
||
``` | ||
source .venv/bin/activate | ||
``` | ||
``` | ||
source .venv/bin/activate | ||
``` | ||
|
||
3. Install [nada-dsl](https://pypi.org/project/nada-dsl/) | ||
3. Install [nada-dsl](https://pypi.org/project/nada-dsl/) from pypi | ||
|
||
``` | ||
pip install nada-dsl | ||
``` | ||
``` | ||
pip install nada-dsl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Use the <strong>[`nada`](/nada)</strong> tool to compile, run and test the program we have just written. More information about the nada tool can be found [here](https://docs.nillion.com/nada). | ||
|
||
1. Add your program to `nada-project.toml` config file | ||
|
||
For the nada tool to know about our program, we need to add the following to the to the `nada-project.toml` config file. | ||
```bash | ||
[[programs]] | ||
path = "src/secret_addition.py" | ||
name = "secret_addition" | ||
prime_size = 128 | ||
``` | ||
|
||
2. Run the `nada build` command to compile programs. | ||
```bash | ||
nada build | ||
``` | ||
|
||
This will compile all programs listed in the nada-project.toml file. You will see the binary files (.nada.bin) outputted to the `target/` directory. | ||
|
||
3. Generate test | ||
```bash | ||
nada generate-test --test-name secret_addition_test secret_addition | ||
``` | ||
|
||
This uses the nada tool to generate a set of test values, that will be stored in `tests/`. Here secret_addition_test is the name of the test, and secret_addition is the name of the program we want to test. You will notice that the test file (`tests/secret_addition_test.yaml`) is automatically populated with `3`s everywhere by default. Later, for the test to pass, we will have to change the output from `3` to the correct output. | ||
|
||
4. Run the program with test values | ||
```bash | ||
nada run secret_addition_test | ||
``` | ||
|
||
Now we run the program. This uses the inputs defined in the test file (tests/secret_addition_test.yaml) and runs the program and prints the result. Make note of the result, we will need it next. | ||
|
||
5. Test the program | ||
```bash | ||
nada test secret_addition_test | ||
``` | ||
|
||
Finally, we test the program. If you run the above command without altering the default values (`3`s) in the test file (`tests/secret_addition_test.yaml`), the test will fail because the expected test output doesn't match the resulting output. Modify the value of `my_output` in the test file and re-test the program. | ||
<strong>Modify test values in `secret_addition_test.yaml`</strong> | ||
```bash | ||
--- | ||
program: secret_addition | ||
inputs: | ||
my_int1: | ||
SecretInteger: "3" | ||
my_int2: | ||
SecretInteger: "3" | ||
expected_outputs: | ||
my_output: | ||
SecretInteger: "6" | ||
``` | ||
<strong>Re-run test</strong> | ||
```bash | ||
nada test secret_addition_test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Let's go through the program line by line to understand what is each part is doing. | ||
|
||
1. First we import all from nada_dsl, the Nada language | ||
```python | ||
from nada_dsl import * | ||
``` | ||
2. Next we create `function nada_main()` - this is the main function that contains our Nada program's code. | ||
```python | ||
from nada_dsl import * | ||
|
||
def nada_main(): | ||
``` | ||
3. Create a party with a name: `Party1` | ||
```python | ||
from nada_dsl import * | ||
|
||
def nada_main(): | ||
|
||
party1 = Party(name="Party1") | ||
``` | ||
|
||
This is a single party program, but you could add more than one party; for example we could define `party2 = Party(name="Party2")`. | ||
4. Create program inputs | ||
```python | ||
from nada_dsl import * | ||
|
||
def nada_main(): | ||
|
||
party1 = Party(name="Party1") | ||
|
||
my_int1 = SecretInteger(Input(name="my_int1", party=party1)) | ||
|
||
my_int2 = SecretInteger(Input(name="my_int2", party=party1)) | ||
``` | ||
|
||
This program has two inputs, both secret integers. Each input must have a `name` and a `party` associated to it. Currently in nada you can only compute on secret or public integers (and rationals by using the `nada-algebra` library). | ||
|
||
5. Compute on the inputs | ||
```python | ||
from nada_dsl import * | ||
|
||
def nada_main(): | ||
|
||
party1 = Party(name="Party1") | ||
|
||
my_int1 = SecretInteger(Input(name="my_int1", party=party1)) | ||
|
||
my_int2 = SecretInteger(Input(name="my_int2", party=party1)) | ||
|
||
new_int = my_int1 + my_int2 | ||
``` | ||
This performs addition to sum the inputs. Check out all the [built in operations available in nada here](/nada-lang-operators). | ||
|
||
6. Return the output of the program | ||
```python | ||
from nada_dsl import * | ||
|
||
def nada_main(): | ||
|
||
party1 = Party(name="Party1") | ||
|
||
my_int1 = SecretInteger(Input(name="my_int1", party=party1)) | ||
|
||
my_int2 = SecretInteger(Input(name="my_int2", party=party1)) | ||
|
||
new_int = my_int1 + my_int2 | ||
|
||
return [Output(new_int, "my_output", party1)] | ||
``` | ||
To output the result of a program, we must provide a name - in this case `my_output` - and a party to whom the output is provided - in this case `party1`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.