diff --git a/sdk/aleo.pyi b/sdk/aleo.pyi new file mode 100644 index 0000000..cf7a286 --- /dev/null +++ b/sdk/aleo.pyi @@ -0,0 +1,110 @@ +class Account: + @staticmethod + def from_private_key(private_key: PrivateKey) -> Account: ... + @property + def private_key(self) -> PrivateKey: ... + @property + def view_key(self) -> ViewKey: ... + @property + def address(self) -> Address: ... + def sign(self, message: bytes) -> Signature: ... + def verify(self, signature: Signature, message: bytes) -> bool: ... + def decrypt(self, record_ciphertext: RecordCiphertext) -> RecordPlaintext: ... + def is_owner(self, record_ciphertext: RecordCiphertext) -> bool: ... + +class Address: + @staticmethod + def from_string(s: str) -> Address: ... + def to_string(self) -> str: ... + +class CoinbasePuzzle: + @staticmethod + def load() -> CoinbasePuzzle: ... + @property + def verifying_key(self) -> CoinbaseVerifyingKey: ... + +class CoinbaseVerifyingKey: + pass + +class ComputeKey: + @property + def address(self) -> Address: ... + @property + def pk_sig(self) -> str: ... + @property + def pr_sig(self) -> str: ... + @property + def sk_prf(self) -> str: ... + +class EpochChallenge: + @staticmethod + def from_json(json: str) -> EpochChallenge: ... + def to_json(self) -> str: ... + +class PrivateKey: + @property + def address(self) -> Address: ... + @property + def compute_key(self) -> ComputeKey: ... + @staticmethod + def from_string(private_key: str) -> PrivateKey: ... + @property + def seed(self) -> str: ... + def sign(self, message: bytes) -> Signature: ... + @property + def sk_sig(self) -> str: ... + @property + def r_sig(self) -> str: ... + def to_string(self) -> str: ... + @property + def view_key(self) -> ViewKey: ... + +class ProverSolution: + @staticmethod + def from_json(json: str) -> ProverSolution: ... + def to_json(self) -> str: ... + @property + def address(self) -> Address: ... + def verify(self, verifying_key: CoinbaseVerifyingKey, + epoch_challenge: EpochChallenge, proof_target: int) -> bool: ... + +class RecordCiphertext: + @staticmethod + def from_string(s: str) -> RecordCiphertext: ... + def to_string(self) -> str: ... + def decrypt(self, view_key: ViewKey) -> RecordPlaintext: ... + def is_owner(self, view_key: ViewKey) -> bool: ... + +class RecordPlaintext: + @staticmethod + def from_string(s: str) -> RecordPlaintext: ... + @property + def owner(self) -> str: ... + @property + def nonce(self) -> str: ... + def serial_number_string(self, private_key: PrivateKey, program_id: str, + record_name: str) -> str: ... + def to_string(self) -> str: ... + +class Signature: + @property + def challenge(self) -> str: ... + @property + def compute_key(self) -> ComputeKey: ... + @staticmethod + def from_string(s: str) -> Signature: ... + @property + def response(self) -> str: ... + @staticmethod + def sign(private_key: PrivateKey, message: bytes) -> Signature: ... + def to_string(self) -> str: ... + def verify(self, address: Address, message: bytes) -> bool: ... + +class ViewKey: + def decrypt(self, record_ciphertext: RecordCiphertext) -> RecordPlaintext: ... + @staticmethod + def from_string(s: str) -> ViewKey: ... + def is_owner(self, record_ciphertext: RecordCiphertext) -> bool: ... + @property + def address(self) -> Address: ... + def to_string(self) -> str: ... diff --git a/sdk/src/account/compute_key.rs b/sdk/src/account/compute_key.rs index 0068f7b..53db5e1 100644 --- a/sdk/src/account/compute_key.rs +++ b/sdk/src/account/compute_key.rs @@ -26,21 +26,25 @@ pub struct ComputeKey(ComputeKeyNative); #[pymethods] impl ComputeKey { /// Returns the address from the compute key. + #[getter] fn address(&self) -> Address { Address::from(self.0.to_address()) } /// Returns the signature public key. + #[getter] fn pk_sig(&self) -> String { self.0.pk_sig().to_string() } /// Returns the signature public randomizer. + #[getter] fn pr_sig(&self) -> String { self.0.pr_sig().to_string() } /// Returns a reference to the PRF secret key. + #[getter] fn sk_prf(&self) -> String { self.0.sk_prf().to_string() } diff --git a/sdk/src/account/mod.rs b/sdk/src/account/mod.rs index 26b989b..89490f6 100644 --- a/sdk/src/account/mod.rs +++ b/sdk/src/account/mod.rs @@ -67,16 +67,19 @@ impl Account { } /// Returns an account private key. + #[getter] fn private_key(&self) -> PrivateKey { self.private_key } /// Returns an account view key. + #[getter] fn view_key(&self) -> ViewKey { self.view_key.clone() } /// Returns an account address. + #[getter] fn address(&self) -> Address { self.address.clone() } diff --git a/sdk/src/account/private_key.rs b/sdk/src/account/private_key.rs index e92e977..6cb0307 100644 --- a/sdk/src/account/private_key.rs +++ b/sdk/src/account/private_key.rs @@ -43,11 +43,13 @@ impl PrivateKey { } /// Derives the account address from an account private key. + #[getter] pub fn address(&self) -> anyhow::Result
{ Ok(Address::from(AddressNative::try_from(&self.0)?)) } /// Derives the account compute key from an account private key. + #[getter] fn compute_key(&self) -> ComputeKey { let compute_key = ComputeKeyNative::try_from(&self.0).unwrap(); ComputeKey::from(compute_key) @@ -60,6 +62,7 @@ impl PrivateKey { } /// Returns the account seed. + #[getter] fn seed(&self) -> String { self.0.seed().to_string() } @@ -70,11 +73,13 @@ impl PrivateKey { } /// Returns the signature secret key. + #[getter] fn sk_sig(&self) -> String { self.0.sk_sig().to_string() } /// Returns the signature randomizer. + #[getter] fn r_sig(&self) -> String { self.0.r_sig().to_string() } @@ -87,6 +92,7 @@ impl PrivateKey { } /// Initializes a new account view key from an account private key. + #[getter] pub fn view_key(&self) -> ViewKey { let view_key = ViewKeyNative::try_from(&self.0).unwrap(); ViewKey::from(view_key) diff --git a/sdk/src/account/record.rs b/sdk/src/account/record.rs index 37515d1..916e477 100644 --- a/sdk/src/account/record.rs +++ b/sdk/src/account/record.rs @@ -86,11 +86,13 @@ impl RecordPlaintext { } /// Returns the owner of the record as a string + #[getter] fn owner(&self) -> String { self.0.owner().to_string() } /// Returns the nonce of the record as a string + #[getter] fn nonce(&self) -> String { self.0.nonce().to_string() } diff --git a/sdk/src/account/signature.rs b/sdk/src/account/signature.rs index 928f8c2..dbdbc52 100644 --- a/sdk/src/account/signature.rs +++ b/sdk/src/account/signature.rs @@ -35,11 +35,13 @@ pub struct Signature(SignatureNative); #[pymethods] impl Signature { /// Returns the verifier challenge. + #[getter] fn challenge(&self) -> String { self.0.challenge().to_string() } /// Returns the signer compute key. + #[getter] fn compute_key(&self) -> ComputeKey { ComputeKey::from(self.0.compute_key()) } @@ -52,6 +54,7 @@ impl Signature { } /// Returns the prover response. + #[getter] fn response(&self) -> String { self.0.response().to_string() } diff --git a/sdk/src/account/view_key.rs b/sdk/src/account/view_key.rs index 3369e9f..80980b4 100644 --- a/sdk/src/account/view_key.rs +++ b/sdk/src/account/view_key.rs @@ -51,7 +51,8 @@ impl ViewKey { } /// Returns the address corresponding to the view key. - fn to_address(&self) -> Address { + #[getter] + fn address(&self) -> Address { let address = self.0.to_address(); Address::from(address) } diff --git a/sdk/src/coinbase/prover_solution.rs b/sdk/src/coinbase/prover_solution.rs index ca61737..c3e12c3 100644 --- a/sdk/src/coinbase/prover_solution.rs +++ b/sdk/src/coinbase/prover_solution.rs @@ -45,6 +45,7 @@ impl ProverSolution { } /// Returns the address of the prover. + #[getter] fn address(&self) -> Address { Address::from(self.0.address()) } diff --git a/sdk/src/coinbase/puzzle.rs b/sdk/src/coinbase/puzzle.rs index 42a0719..c0a534e 100644 --- a/sdk/src/coinbase/puzzle.rs +++ b/sdk/src/coinbase/puzzle.rs @@ -31,6 +31,7 @@ impl CoinbasePuzzle { } /// Returns the coinbase verifying key. + #[getter] fn verifying_key(&self) -> anyhow::Result { let verifying_key = self.0.coinbase_verifying_key().clone(); Ok(CoinbaseVerifyingKey::from(verifying_key)) diff --git a/sdk/test.py b/sdk/test.py index 41f92e3..f853094 100644 --- a/sdk/test.py +++ b/sdk/test.py @@ -9,16 +9,16 @@ def test_sanity(): private_key = aleo.PrivateKey.from_string(c_private_key) assert str(private_key) == c_private_key - assert str(private_key.view_key()) == c_view_key - assert str(private_key.address()) == c_address + assert str(private_key.view_key) == c_view_key + assert str(private_key.address) == c_address view_key = aleo.ViewKey.from_string(c_view_key) assert str(view_key) == c_view_key - assert view_key == private_key.view_key() + assert view_key == private_key.view_key address = aleo.Address.from_string(c_address) assert str(address) == c_address - assert address == private_key.address() + assert address == private_key.address def test_decrypt_success(): c_plaintext = """{ @@ -47,14 +47,14 @@ def test_signature_verify(): def test_account_sanity(): private_key = aleo.PrivateKey.from_string("APrivateKey1zkp3dQx4WASWYQVWKkq14v3RoQDfY2kbLssUj7iifi1VUQ6") account = aleo.Account.from_private_key(private_key) - assert account.private_key() == private_key + assert account.private_key == private_key assert account == aleo.Account.from_private_key(private_key) message = bytes("asd", "utf-8") bad_message = bytes("qwe", "utf-8") signature = account.sign(message) assert account.verify(signature, message) assert not account.verify(signature, bad_message) - assert signature.verify(account.address(), message) + assert signature.verify(account.address, message) def test_coinbase(): address = aleo.Address.from_string("aleo16xwtrvntrfnan84sy3qg2gdkkp5u5p7sjc882lx8n06fjx2k0yqsklw8sv") @@ -63,7 +63,7 @@ def test_coinbase(): challenge = aleo.EpochChallenge.from_json(challenge_json) solution = aleo.ProverSolution.from_json(solution_json) - assert solution.address() == address + assert solution.address == address assert str(challenge) == challenge_json assert str(solution) == solution_json