Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/example_jsonrpc_get_blockchain_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

async def main() -> None:
client_url = "https://testnet1.pactus.org/jsonrpc"
client = PactusOpenRPCClient(
headers={},
client_url=client_url)
client = PactusOpenRPCClient(headers={}, client_url=client_url, timeout=300)

res = await client.pactus.blockchain.get_blockchain_info()

Expand Down
4 changes: 1 addition & 3 deletions examples/example_jsonrpc_get_node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

async def main() -> None:
client_url = "https://testnet1.pactus.org/jsonrpc"
client = PactusOpenRPCClient(
headers={},
client_url=client_url)
client = PactusOpenRPCClient(headers={}, client_url=client_url, timeout=300)

res = await client.pactus.network.get_node_info()

Expand Down
4 changes: 2 additions & 2 deletions examples/example_key_generation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse

from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.crypto.address import AddressType
from pactus.crypto.bls.private_key import PrivateKey as BLSPrivateKey
from pactus.crypto.ed25519.private_key import PrivateKey as Ed25519PrivateKey
Expand Down Expand Up @@ -28,7 +28,7 @@ def main() -> None:
args = parser.parse_args()

if args.testnet:
CryptoConfig.use_testnet()
HRP.use_testnet()

match AddressType(args.address_type):
case AddressType.VALIDATOR:
Expand Down
4 changes: 2 additions & 2 deletions examples/example_transfer_transaction_bls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.crypto.address import Address
from pactus.crypto.bls.private_key import PrivateKey
from pactus.transaction.transaction import Transaction
from pactus.amount import Amount


def main() -> None:
CryptoConfig.use_testnet()
HRP.use_testnet()

lock_time = 1_735_096
memo = "This is a test transaction"
Expand Down
4 changes: 2 additions & 2 deletions examples/example_transfer_transaction_ed25519.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.crypto.address import Address
from pactus.crypto.ed25519.private_key import PrivateKey
from pactus.transaction.transaction import Transaction
from pactus.amount import Amount


def main() -> None:
CryptoConfig.use_testnet()
HRP.use_testnet()

lock_time = 1_735_096
memo = "This is a test transaction"
Expand Down
3 changes: 0 additions & 3 deletions pactus/crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .crypto import CryptoConfig

__all__ = ["CryptoConfig"]
6 changes: 3 additions & 3 deletions pactus/crypto/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import Enum

from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.utils import utils

# Address format: hrp + `1` + type + data + checksum
Expand Down Expand Up @@ -34,7 +34,7 @@ def from_string(cls, text: str) -> Address:
return bytes([0])

hrp, typ, data = utils.decode_to_base256_with_type(text)
if hrp != CryptoConfig.ADDRESS_HRP:
if hrp != HRP.ADDRESS_HRP:
msg = f"Invalid HRP: {hrp}"
raise ValueError(msg)

Expand All @@ -57,7 +57,7 @@ def string(self) -> str:
return TREASURY_ADDRESS_STRING

return utils.encode_from_base256_with_type(
CryptoConfig.ADDRESS_HRP,
HRP.ADDRESS_HRP,
self.data[0],
self.data[1:],
)
Expand Down
12 changes: 6 additions & 6 deletions pactus/crypto/bls/private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import secrets
from math import ceil, log2

from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.utils import utils

from .bls12_381.bls_sig_g1 import sign
Expand All @@ -17,12 +17,12 @@


class PrivateKey:
def __init__(self, scalar: any) -> None:
self.scalar = scalar
def __init__(self, scalar: int) -> None:
self.scalar = scalar % curve_order

@classmethod
def from_bytes(cls, buffer: bytes) -> PrivateKey:
return cls(int.from_bytes(buffer, "big") % curve_order)
return cls(int.from_bytes(buffer, "big"))

@classmethod
def key_gen(cls, ikm: bytes = [], key_info: bytes = b"") -> PrivateKey:
Expand All @@ -47,7 +47,7 @@ def random(cls) -> PrivateKey:
def from_string(cls, text: str) -> PrivateKey:
hrp, typ, data = utils.decode_to_base256_with_type(text)

if hrp != CryptoConfig.PRIVATE_KEY_HRP:
if hrp != HRP.PRIVATE_KEY_HRP:
msg = f"Invalid hrp: {hrp}"
raise ValueError(msg)

Expand All @@ -67,7 +67,7 @@ def raw_bytes(self) -> bytes:

def string(self) -> str:
return utils.encode_from_base256_with_type(
CryptoConfig.PRIVATE_KEY_HRP,
HRP.PRIVATE_KEY_HRP,
SIGNATURE_TYPE_BLS,
self.raw_bytes(),
)
Expand Down
6 changes: 3 additions & 3 deletions pactus/crypto/bls/public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from ripemd.ripemd160 import ripemd160

from pactus.crypto import CryptoConfig
from pactus.crypto.address import Address, AddressType
from pactus.crypto.hrp import HRP
from pactus.utils import utils

from .bls12_381.bls_sig_g1 import aggregate_pubs, verify
Expand All @@ -23,7 +23,7 @@ def __init__(self, point_g2: any) -> None:
def from_string(cls, text: str) -> PublicKey:
hrp, typ, data = utils.decode_to_base256_with_type(text)

if hrp != CryptoConfig.PUBLIC_KEY_HRP:
if hrp != HRP.PUBLIC_KEY_HRP:
msg = f"Invalid hrp: {hrp}"
raise ValueError(msg)

Expand Down Expand Up @@ -51,7 +51,7 @@ def raw_bytes(self) -> bytes:

def string(self) -> str:
return utils.encode_from_base256_with_type(
CryptoConfig.PUBLIC_KEY_HRP,
HRP.PUBLIC_KEY_HRP,
SIGNATURE_TYPE_BLS,
self.raw_bytes(),
)
Expand Down
6 changes: 3 additions & 3 deletions pactus/crypto/ed25519/private_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cryptography.hazmat.primitives.asymmetric import ed25519

from pactus.crypto import CryptoConfig
from pactus.crypto.hrp import HRP
from pactus.utils import utils

from .public_key import PublicKey
Expand All @@ -29,7 +29,7 @@ def random(cls) -> PrivateKey:
def from_string(cls, text: str) -> PrivateKey:
hrp, typ, data = utils.decode_to_base256_with_type(text)

if hrp != CryptoConfig.PRIVATE_KEY_HRP:
if hrp != HRP.PRIVATE_KEY_HRP:
msg = f"Invalid hrp: {hrp}"
raise ValueError(msg)

Expand All @@ -49,7 +49,7 @@ def raw_bytes(self) -> bytes:

def string(self) -> str:
return utils.encode_from_base256_with_type(
CryptoConfig.PRIVATE_KEY_HRP,
HRP.PRIVATE_KEY_HRP,
SIGNATURE_TYPE_ED25519,
self.raw_bytes(),
)
Expand Down
6 changes: 3 additions & 3 deletions pactus/crypto/ed25519/public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from cryptography.hazmat.primitives.asymmetric import ed25519
from ripemd.ripemd160 import ripemd160

from pactus.crypto import CryptoConfig
from pactus.crypto.address import Address, AddressType
from pactus.crypto.hrp import HRP
from pactus.utils import utils

from .signature import SIGNATURE_TYPE_ED25519, Signature
Expand All @@ -23,7 +23,7 @@ def __init__(self, pub: ed25519.Ed25519PublicKey) -> None:
def from_string(cls, text: str) -> PublicKey:
hrp, typ, data = utils.decode_to_base256_with_type(text)

if hrp != CryptoConfig.PUBLIC_KEY_HRP:
if hrp != HRP.PUBLIC_KEY_HRP:
msg = f"Invalid hrp: {hrp}"
raise ValueError(msg)

Expand All @@ -44,7 +44,7 @@ def raw_bytes(self) -> bytes:

def string(self) -> str:
return utils.encode_from_base256_with_type(
CryptoConfig.PUBLIC_KEY_HRP,
HRP.PUBLIC_KEY_HRP,
SIGNATURE_TYPE_ED25519,
self.raw_bytes(),
)
Expand Down
2 changes: 1 addition & 1 deletion pactus/crypto/crypto.py → pactus/crypto/hrp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CryptoConfig:
class HRP:
ADDRESS_HRP = "pc"
PUBLIC_KEY_HRP = "public"
PRIVATE_KEY_HRP = "secret"
Expand Down
3 changes: 0 additions & 3 deletions pactus/transaction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .transaction import Transaction

__all__ = ["Transaction"]
Loading