Skip to content

Commit

Permalink
Updates for SUI 0.22.1 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Jan 23, 2023
1 parent 1e81fb8 commit 1775b15
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Updated SuiSystemState result definition to include `safe_mode` field as per SUI 0.22.1
- Updated CheckpointSummary result definition to include `timestamp_ms` field as per SUI 0.22.1

### Removed

## [0.9.0] 2023-01-20
Expand Down
18 changes: 12 additions & 6 deletions pysui/sui/sui_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# -*- coding: utf-8 -*-


"""Sui Crpto Utilities."""
"""Sui Crpto Keys and Keypairs."""

from abc import abstractmethod
import base64
import hashlib
from typing import Union
Expand Down Expand Up @@ -154,13 +153,16 @@ def __init__(self, indata: bytes) -> None:
raise SuiInvalidKeyPair(f"Private Key expects {SECP256R1_PRIVATEKEY_BYTES_LEN} bytes, found {dlen}")
super().__init__(SignatureScheme.SECP256R1, indata)
self._signing_key = ecdsa.SigningKey.from_string(indata, ecdsa.NIST256p, hashfunc=hashlib.sha256)
self._pad_byte = int(0).to_bytes(1, "little")
self._pad_byte = int(1).to_bytes(1, "little")

# FIXME: Need to understand where the recovery ID comes from
def sign(self, data: bytes) -> bytes:
"""SECP256R1 sign data bytes."""
last_byte = data[-1].to_bytes(1, "little")
core_sig = self._signing_key.sign_deterministic(data)
core_sig += last_byte # self._pad_byte
core_sig = self._signing_key.sign_deterministic(data, hashfunc=hashlib.sha256)
print(f"Sig size = {len(core_sig)}")
print(f"Last byte = {core_sig[-1]}")
core_sig += self._pad_byte
# core_sig[-1].to_bytes(1, "little") # data[-1].to_bytes(1, "little") # self._pad_byte
return core_sig


Expand Down Expand Up @@ -251,6 +253,7 @@ def from_bytes(cls, indata: bytes) -> KeyPair:


# Secp256
# TODO: Change to use the ecdsa library


class SuiPublicKeySECP256K1(SuiPublicKey):
Expand All @@ -264,6 +267,7 @@ def __init__(self, indata: bytes) -> None:
self._verify_key = secp256k1.PublicKey(indata, raw=True)


# TODO: Change to use the ecdsa library
class SuiPrivateKeySECP256K1(SuiPrivateKey):
"""A SECP256K1 Private Key."""

Expand All @@ -283,6 +287,7 @@ def sign(self, data: bytes) -> bytes:
return bytes(sig_ba)


# TODO: Change to use the ecdsa library
class SuiKeyPairSECP256K1(SuiKeyPair):
"""A SuiKey Pair."""

Expand Down Expand Up @@ -360,6 +365,7 @@ def _valid_pubkey(key_valmethod: str, pub_key: bytes) -> Union[None, TypeError,
raise vexc


# TODO: Change to use the ecdsa library
def _generate_secp256k1(
mnemonics: Union[str, list[str]] = "", derv_path: str = None
) -> tuple[str, SuiKeyPairSECP256K1]:
Expand Down
1 change: 1 addition & 0 deletions pysui/sui/sui_txresults/complex_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ class CheckpointSummary(DataClassJsonMixin):
network_total_transactions: int
sequence_number: int
next_epoch_committee: Optional[list[int]]
timestamp_ms: int


# Event query results
Expand Down
1 change: 1 addition & 0 deletions pysui/sui/sui_txresults/single_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ class SuiSystemState(DataClassJsonMixin):
epoch: int
parameters: StateParameters
reference_gas_price: int
safe_mode: bool
stake_subsidy: StakeSubsidy
storage_fund: Union[dict, int]
treasury_cap: Union[dict, int]
Expand Down

0 comments on commit 1775b15

Please sign in to comment.