-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to use python to wrap Aleo functionality
- Loading branch information
1 parent
16514ff
commit 43ed1b7
Showing
7 changed files
with
62 additions
and
1 deletion.
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
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,9 @@ | ||
[package] | ||
name = "aleo_python" | ||
authors = ["Mike Turner"] | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
pyo3 = { version = "0.18.2", features = ["extension-module"] } | ||
snarkvm = { version = "0.9.14", features = ["console"] } |
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,16 @@ | ||
import sys | ||
from aleo_python import hash_int | ||
|
||
def hash_integer(integer): | ||
return hash_int(integer) | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) > 1: | ||
try: | ||
input_integer = int(sys.argv[1]) | ||
hashed_integer = hash_integer(input_integer) | ||
print(f"The hash of {input_integer} is {hashed_integer}.") | ||
except ValueError: | ||
print("Invalid input. Please provide an integer.") | ||
else: | ||
print("Please provide an integer as a command line argument.") |
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,10 @@ | ||
#!/bin/bash | ||
|
||
## This script assumes you have already installed Rust 1.6+ and Python 3.8.5+ | ||
## The script below will install the Aleo Python bindings and create the aleo_python library allowing you to use | ||
## the Aleo implementation of the Poseidon hash function in Python. | ||
python -m venv .env | ||
source .env/bin/activate | ||
pip install maturin | ||
maturin develop | ||
python hash_integer.py 5 |
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,13 @@ | ||
use super::*; | ||
use snarkvm::console::algorithms::Poseidon2; | ||
use snarkvm::prelude::{Hash, Testnet3, Field}; | ||
use ToString; | ||
|
||
// Takes a poseiden hash of an integer and returns the hash as a string | ||
#[pyfunction] | ||
pub fn hash_int(a: u64) -> PyResult<String> { | ||
let field = Field::from_u64(a); | ||
let hasher = Poseidon2::setup("Poseidon2").unwrap(); | ||
let hash: Field<Testnet3> = hasher.hash(&[field]).unwrap(); | ||
Ok(hash.to_string()) | ||
} |
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,12 @@ | ||
use pyo3::prelude::*; | ||
|
||
pub mod hash; | ||
pub use hash::*; | ||
|
||
/// A Python module implemented in Rust. | ||
#[pymodule] | ||
fn aleo_python(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(hash_int, m)?)?; | ||
|
||
Ok(()) | ||
} |
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 +1 @@ | ||
mod algebra; | ||
mod algebra; |