Skip to content

Commit

Permalink
Merge pull request #21 from NillionNetwork/dave-restructure
Browse files Browse the repository at this point in the history
Restructure for DevEx
  • Loading branch information
oceans404 authored May 3, 2024
2 parents 0e7a1cb + 6e0a829 commit 1ae7092
Show file tree
Hide file tree
Showing 65 changed files with 111 additions and 175 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

This is a python starter repo for building on the Nillion Network. Complete environment setup, then run the examples:

- To run multi party examples, go to the [client_multi_party_compute](./client_multi_party_compute) folder.
- To run multi party examples, go to the [multi party compute](examples_and_tutorials/core_concept_multi_party_compute) folder.

- To run single party examples, go to the [client_single_party_compute](./client_single_party_compute) folder.
- To run single party examples, go to the [single party compute](examples_and_tutorials/core_concept_single_party_compute) folder.

- To run permissions examples (storing and retrieving permissioned secrets, revoking permissions, etc.), go to the [permissions](./permissions) folder.
- To run permissions examples (storing and retrieving permissioned secrets, revoking permissions, etc.), go to the [permissions](examples_and_tutorials/core_concept_permissions) folder.

### Prerequisites: Install the CLI Dependencies

The `run-local-cluster` tool spins up `anvil` under the hood, so you need to have `foundry` installed. The [`bootstrap-local-environment.sh`](./bootstrap-local-environment.sh) file uses `pidof` and `grep`.
The `nillion-devnet` tool spins up `anvil` under the hood, so you need to have `foundry` installed. The [`bootstrap-local-environment.sh`](./bootstrap-local-environment.sh) file uses `pidof` and `grep`.

- [Install `foundry`](https://book.getfoundry.sh/getting-started/installation)
- [Install `pidof`](https://command-not-found.com/pidof)
Expand Down
8 changes: 4 additions & 4 deletions compile_programs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ echo "Now try running an example:"

echo "----------single party compute --------------"

echo "Code for single party compute lives in the client_single_party_compute folder"
echo "📋 to run single party compute - addition_simple program: 'cd client_single_party_compute && python3 addition_simple.py'"
echo "Code for single party compute lives in the examples_and_tutorials/core_concept_client_single_party_compute folder"
echo "📋 to run single party compute - addition_simple program: 'cd examples_and_tutorials/core_concept_client_single_party_compute && python3 addition_simple.py'"

echo "----------multi party compute --------------"

echo "Code for single party compute lives in the client_multi_party_compute folder"
echo "📋 to run multi party compute in 3 steps - addition_simple_multi_party_3: 'cd client_multi_party_compute && python3 01_store_secret_party1.py'"
echo "Code for multi party compute lives in the examples_and_tutorials/core_concept_multi_party_compute folder"
echo "📋 to run multi party compute in 3 steps - addition_simple_multi_party_3: 'cd examples_and_tutorials/core_concept_multi_party_compute && python3 01_store_secret_party1.py'"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
CONFIG_PARTY_1
)

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -26,7 +26,7 @@ async def main():
user_id_1 = client_1.user_id()


program_mir_path=f"../programs-compiled/{CONFIG_PROGRAM_NAME}.nada.bin"
program_mir_path=f"../../programs-compiled/{CONFIG_PROGRAM_NAME}.nada.bin"

# 1st Party stores program
action_id = await client_1.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CONFIG_N_PARTIES
)

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
store_secret_party_1 = importlib.import_module("01_store_secret_party1")
store_secret_party_n = importlib.import_module("02_store_secret_party_n")

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The 3-part Multi Party example assumes there is a stored program that meets the
For example before running addition_simple_multi_party.py, compile all programs and check that addition_simple_multi_party.nada.bin exists in the compiled-programs folder.

```bash
cd ..
cd ../..
./compile_programs.sh
```

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down Expand Up @@ -35,7 +35,7 @@ async def main(args = None):
writer_user_id = writer.user_id()
print(writer_user_id, args.retriever_user_id)

# Writer gives themself default permissions
# Writer gives themself default core_concept_permissions
permissions = nillion.Permissions.default_for_user(writer_user_id)
# Writer gives the reader permission to read/retrieve secret
permissions.add_retrieve_permissions(set([args.retriever_user_id, writer_user_id]))
Expand All @@ -46,7 +46,7 @@ async def main(args = None):
else "not allowed"
)
if result == "not allowed":
raise Exception("failed to set permissions")
raise Exception("failed to set core_concept_permissions")

print(f"ℹ️ Permissions set: Reader {args.retriever_user_id} is {result} to retrieve the secret")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down Expand Up @@ -49,7 +49,7 @@ async def main(args = None):
raise Exception("failed to create valid permissions object")

# Update the permission
print(f"ℹ️ Updating permissions for secret: {args.store_id}.")
print(f"ℹ️ Updating permissions for secret: {args.store_id}.")
print(f"ℹ️ Reset permissions so that user id {args.revoked_user_id} is {result} to retrieve object.", file=sys.stderr)
await writer.update_permissions( cluster_id, args.store_id , new_permissions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
retrieve_secret = importlib.import_module("03_retrieve_secret")
revoke_read_permissions = importlib.import_module("04_revoke_read_permissions")

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Before running through examples, `./bootstrap-local-environment.sh` creates user
4. The writer revokes secret permissions by rewriting them
5. The reader tries to retrieve the secret, but no longer has access to it

To run through the example flow, simply run the python scripts in order. The output of a script will show you what to run next. Below gives the structure of the commands needed.

```shell
cd permissions
python3 01_fetch_reader_userid.py
python3 02_store_permissioned_secret.py --retriever_user_id {READER_USER_ID}
python3 03_retrieve_secret.py --store_id {STORE_ID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ These compute examples only involve one party.
For example before running addition_simple.py, compile all programs and check that addition_simple.nada.bin exists in the compiled-programs folder.

```bash
cd ..
cd ../..
./compile_programs.sh
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="addition_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="circuit_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="circuit_simple_2"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="complex"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from math import sqrt
import pytest

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -27,7 +27,7 @@ async def main():
party_1_name="Party1"
out_party_name="OutParty"
program_name="correlation_coefficient"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down Expand Up @@ -67,7 +67,7 @@ async def main():
secret_bindings.add_input_party(party_0_name, party_id)
secret_bindings.add_input_party(party_1_name, party_id)

# Give permissions to owner to compute with my vote
# Give core_concept_permissions to owner to compute with my vote
secret_permissions = nillion.Permissions.default_for_user(user_id)
secret_permissions.add_compute_permissions({
user_id: {program_id},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="division_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="input_integer"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="input_single"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -22,7 +22,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="modulo_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -23,7 +23,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="multiplication_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -21,7 +21,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="nada_fn_composition"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dotenv import load_dotenv

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
from helpers.nillion_client_helper import create_nillion_client
from helpers.nillion_keypath_helper import getUserKeyFromFile, getNodeKeyFromFile

Expand All @@ -21,7 +21,7 @@ async def main():
user_id = client.user_id()
party_name="Party1"
program_name="nada_fn_simple"
program_mir_path=f"../programs-compiled/{program_name}.nada.bin"
program_mir_path=f"../../programs-compiled/{program_name}.nada.bin"

# store program
action_id = await client.store_program(
Expand Down
Loading

0 comments on commit 1ae7092

Please sign in to comment.