Skip to content

Commit 34a402e

Browse files
committed
updated readme
1 parent 42d84e1 commit 34a402e

File tree

4 files changed

+69
-12
lines changed

4 files changed

+69
-12
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "iop-python"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

+66-9
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,72 @@ maturin develop
2727

2828
## Usage
2929

30-
`hydra.py` contains a module that interacts with the hydra testnet. To use the module, you can import the `HydraWallet` class from api/hydra.py.
30+
This code snippet contains a python wrapper over several Rust functions that interact with the IOP SDK and perform various operations related to the IOP blockchain. Here is a brief description of some function:
3131

3232
```python
33-
from hydra import HydraWallet, HydraChain
33+
import iop_python as iop
3434
```
35-
A example method that verifies a signed statement can be found in the module
35+
36+
- `get_hyd_vault`: Initializes a Hydra vault and returns the admin information as a JSON string.
37+
```python
38+
password = "horse-staple-battery"
39+
network = "devnet"
40+
hyd_vault = iop.get_hyd_vault(phrase,password,network)
41+
```
42+
- `get_morpheus_vault`: Initializes a Morpheus vault and returns the admin information as a JSON string.
43+
```python
44+
password = "horse-staple-battery"
45+
morpheus_vault = iop.get_morpheus_vault(phrase,password)
46+
```
47+
- `generate_nonce`: Generates a random nonce and returns it as a string.
48+
```python
49+
phrase = iop.generate_nonce()
50+
print(nonce)
51+
>>> "uVIc9J4UjKx8tRs6HUEDQElksBCtF9VnHb439boVmB9cw"
52+
```
53+
- `generate_phrase`: Generates a random mnemonic phrase and returns it as a string.
54+
```python
55+
phrase = iop.generate_phrase()
56+
print(phrase)
57+
>>> "blind market ability shoot topple round inmate pass lunch symbol average alpha party notice switch sea pass toy alien fuel pull angle weather scan"
58+
```
59+
- `generate_did_by_morpheus`: Generates a DID (Decentralized Identifier) using a Morpheus vault and returns it as a string.
60+
```python
61+
password = "horse-staple-battery"
62+
morpheus_vault = iop.get_morpheus_vault(phrase,password)
63+
did = iop.generate_did_by_morpheus(morpheus_vault)
64+
print(did)
65+
>>> did:morpheus:ezbeWGSY2dqcUBqT8K7R14xr
66+
```
67+
- `sign_witness_statement`: Signs a witness statement using a Morpheus vault and returns the signed statement as a JSON string.
68+
```python
69+
# network can be mainnet, devnet or testnet
70+
network = "devnet"
71+
vault = iop.get_hyd_vault(phrase,password,network)
72+
statement = {
73+
"name":"Buki Offor",
74+
"street": "Brick City Estate",
75+
"dob": "01/03/1996",
76+
"city": "Abuja",
77+
"country": "Nigeria",
78+
"zipcode": "987554",
79+
80+
}
81+
signed_witness_statement = iop.sign_witness_statement(vault,statement,password)
82+
print(json.loads(signed_witness_statement))
83+
```
84+
- `generate_transaction`: Builds a transaction to transfer a certain amount of tokens to a specified recipient using a Hydra vault and returns the transaction data as a JSON string. This transaction data can be sent to a node to validate and perform the transaction.
85+
86+
```python
87+
receiver = "taQb8gfnetDt6KtRH3n11M3APMzrWiBhhg"
88+
amount = "100"
89+
nonce = 1
90+
key = 0
91+
network = "devnet"
92+
tx_data = iop.generate_transaction(vault,receiver,amount,nonce,password,key,network)
93+
```
94+
95+
- `verify_signed_statement`: Verifies the signature of a signed witness statement and returns a boolean indicating whether the signature is valid.
3696

3797
```python
3898
chain = HydraChain()
@@ -46,11 +106,8 @@ result = chain.verify_signed_statement(signed_statement)
46106
print(result)
47107
>>> True
48108
```
109+
- `validate_statement_with_did`: Validates a signed witness statement using a DID document and returns the validation result as a JSON string.
110+
- `sign_did_statement`: Signs a data payload using a Morpheus vault and returns the signed data and the corresponding public key as strings.
49111

50-
## WALLET APPLICATION
51-
52-
To spin up the wallet application run the command below in the base directory
53112

54-
```bash
55-
python3 app.py
56-
```
113+
These functions are intended to be used as Python module functions and can be imported and called from Python code.

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn iop_python(_py: Python, m: &PyModule) -> PyResult<()> {
317317
m.add_function(wrap_pyfunction!(get_hyd_vault, m)?)?;
318318
m.add_function(wrap_pyfunction!(get_new_acc_on_vault, m)?)?;
319319
m.add_function(wrap_pyfunction!(validate_statement_with_did, m)?)?;
320-
// m.add("VaultCouldNotBeUnwrapped", PanicException::new_err("VaultCouldNotBeUnwrapped") )?;
320+
321321

322322

323323
Ok(())

0 commit comments

Comments
 (0)