Skip to content

Commit

Permalink
Fix SDK RTD
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Jan 4, 2024
1 parent 3ede25e commit eaeffdc
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 6 deletions.
4 changes: 2 additions & 2 deletions sdk/docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
'python': ('https://docs.python.org/3', None)
}

autoapi_dirs = ['../../']
autoapi_file_patterns = ['aleo.pyi']
autoapi_dirs = ['./', '../../python/aleo']
autoapi_file_patterns = ['__init__.pyi']
autoapi_generate_api_docs = True
autoapi_add_toctree_entry = False
autoapi_keep_files = False
Expand Down
14 changes: 14 additions & 0 deletions sdk/docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ Working with accounts
>>> same_account = aleo.Account.from_private_key(private_key)
>>> assert account == same_account

Encrypted key materials
************************************

.. doctest::

>>> ciphertext = aleo.Ciphertext.from_string(
... "ciphertext1qvqt0sp0pp49gjeh50alfalt7ug3g8y7ha6\
... cl3jkavcsnz8d0y9jwr27taxfrwd5kly8lah53qure3vxav\
... 6zxr7txattdvscv0kf3vcuqv9cmzj32znx4uwxdawcj3273\
... zhgm8qwpxqczlctuvjvc596mgsqjxwz37f")
>>> decrypted = aleo.Encryptor.decrypt_private_key_with_secret(ciphertext, "qwe123")
>>> account = aleo.Account.from_private_key(decrypted)
>>> str(account)
'aleo1w58eg85ckl76c0pzzf4mdg2y39t9t7jfvp9u2fvnj2a2t8aquqpqrlycqt'

Working with signatures
***********************
Expand Down
7 changes: 6 additions & 1 deletion sdk/python/aleo/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class ComputeKey:
def pr_sig(self) -> Group: ...
def sk_prf(self) -> Scalar: ...

class Encryptor:
@staticmethod
def encrypt_private_key_with_secret(private_key: PrivateKey, secret: str) -> Ciphertext: ...
@staticmethod
def decrypt_private_key_with_secret(ciphertext: Ciphertext, secret: str) -> PrivateKey: ...

class EpochChallenge:
@staticmethod
Expand Down Expand Up @@ -207,7 +212,7 @@ class Network:
@staticmethod
def name() -> str: ...
@staticmethod
def version() -> int: ...
def id() -> int: ...
@staticmethod
def edition() -> int: ...
@staticmethod
Expand Down
193 changes: 193 additions & 0 deletions sdk/python/aleo/_aleolib.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
from __future__ import annotations

class Account:
pass


class Address:
pass


class Authorization:
pass


class Boolean:
pass


class Ciphertext:
pass


class Credits:
pass


class CoinbasePuzzle:
pass


class CoinbaseVerifyingKey:
pass


class ComputeKey:
pass


class EpochChallenge:
pass


class Execution:
pass


class Fee:
pass


class Field:
pass


class Group:
pass


class Identifier:
pass


class I8:
pass


class I16:
pass


class I32:
pass


class I64:
pass


class I128:
pass


class Literal:
pass


class Locator:
pass


class Network:
pass


class MicroCredits:
pass


class Plaintext:
pass


class PrivateKey:
pass


class Process:
pass


class Program:
pass


class ProgramID:
pass


class ProverSolution:
pass


class ProvingKey:
pass


class Query:
pass


class RecordCiphertext:
pass


class RecordPlaintext:
pass


class Response:
pass


class Scalar:
pass


class Signature:
pass


class Trace:
pass


class Transaction:
pass


class Transition:
pass


class U8:
pass


class U16:
pass


class U32:
pass


class U64:
pass


class U128:
pass


class Value:
pass


class VerifyingKey:
pass


class ViewKey:
pass

10 changes: 7 additions & 3 deletions sdk/python/aleo/encryptor.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from __future__ import annotations

from ._aleolib import PrivateKey, Ciphertext, Field, Network, Identifier, Plaintext, Literal
from . import PrivateKey, Ciphertext, Field, Network, Identifier, Plaintext, Literal


class Encryptor:
"""Class for encrypting and decrypting Aleo key material into ciphertext.
"""
@staticmethod
# Encrypt a private key into ciphertext using a secret
def encrypt_private_key_with_secret(private_key: PrivateKey, secret: str) -> Ciphertext:
"""Encrypts a private key into ciphertext using a secret.
"""
seed = private_key.seed()
return Encryptor.__encrypt_field(seed, secret, "private_key")

@staticmethod
# Decrypt a private key from ciphertext using a secret
def decrypt_private_key_with_secret(ciphertext: Ciphertext, secret: str) -> PrivateKey:
"""Decrypts a private key from ciphertext using a secret.
"""
seed = Encryptor.__decrypt_field(ciphertext, secret, "private_key")
return PrivateKey.from_seed(seed)

Expand Down

0 comments on commit eaeffdc

Please sign in to comment.