starcoin.sdk package¶
Submodules¶
starcoin.sdk.auth_key module¶
Provides AuthKey class for holding Diem authentication key and generating account address, prefix from it.
- class starcoin.sdk.auth_key.AuthKey(data: bytes)[source]¶
Bases:
object
Diem Authentication Key
Wraps authentication key bytes, derives account address and authentication key prefix.
- account_address() starcoin.starcoin_types.AccountAddress [source]¶
- data: bytes¶
- static from_public_key(public_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey) starcoin.sdk.auth_key.AuthKey [source]¶
starcoin.sdk.client module¶
- class starcoin.sdk.client.Client(url)[source]¶
Bases:
object
Starcoin sdk client
- execute(operation)[source]¶
Execute a rpc request operation operation = {
“rpc_method”: $rpc_method, “params”: $params,
} such as: operation = {
“rpc_method”: “node.info”, “params”: None,
}
- get_account_resource(addr: str) starcoin.starcoin_types.AccountResource [source]¶
- get_block_reward(block_number: int)[source]¶
get block reward by blcok_number, block_number shoule less than header.block_number return coin_reward, author, gas_fee
- submit(txn: Union[starcoin.starcoin_types.SignedUserTransaction, str])[source]¶
starcoin.sdk.local_account module¶
Provides LocalAccount class for holding local account private key.
LocalAccount provides operations we need for creating auth key, account address and signing raw transaction.
- class starcoin.sdk.local_account.LocalAccount(private_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey)[source]¶
Bases:
object
LocalAccount is like a wallet account
WARN: This is handy class for creating tests for your application, but may not ideal for your production code, because it uses a specific implementaion of ed25519 and requires loading your private key into memory and hand over to code from external. You should always choose more secure way to handle your private key (e.g. https://en.wikipedia.org/wiki/Hardware_security_module) in production and do not give your private key to any code from external if possible.
- property account_address: starcoin.starcoin_types.AccountAddress¶
- property auth_key: starcoin.sdk.auth_key.AuthKey¶
- compliance_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey¶
- property compliance_public_key_bytes: bytes¶
- static generate() starcoin.sdk.local_account.LocalAccount [source]¶
Generate a random private key and initialize local account
- private_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey¶
- property public_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey¶
- property public_key_bytes: bytes¶
- sign(txn: starcoin.starcoin_types.RawTransaction) starcoin.starcoin_types.SignedUserTransaction [source]¶
Create signed transaction for given raw transaction
starcoin.sdk.utils module¶
Utilities for data type converting, construction and hashing.
- starcoin.sdk.utils.account_address(addr: Union[starcoin.starcoin_types.AccountAddress, bytes, str]) starcoin.starcoin_types.AccountAddress [source]¶
convert an account address from hex-encoded or bytes into starcoin_types.AccountAddress
Returns given address if it is starcoin_types.AccountAddress already
- starcoin.sdk.utils.account_address_bytes(addr: Union[starcoin.starcoin_types.AccountAddress, str]) bytes [source]¶
convert starcoin_types.AccountAddress or hex-encoded account address into bytes
- starcoin.sdk.utils.account_address_hex(addr: Union[starcoin.starcoin_types.AccountAddress, str]) str [source]¶
convert starcoin_types.AccountAddress into hex-encoded string
This function converts given parameter into account address bytes first, then convert bytes into hex-encoded string
- starcoin.sdk.utils.create_signed_transaction(txn: starcoin.starcoin_types.RawTransaction, public_key: bytes, signature: bytes) starcoin.starcoin_types.SignedUserTransaction [source]¶
create single signed starcoin_types.SignedTransaction
- starcoin.sdk.utils.currency_code(code: str) starcoin.starcoin_types.TypeTag [source]¶
converts currency code string to starcoin_types.TypeTag
- starcoin.sdk.utils.currency_user_code(address: str, code: str) starcoin.starcoin_types.TypeTag [source]¶
converts currency code string to starcoin_types.TypeTag
- starcoin.sdk.utils.payload_bcs_decode(payload: str) Union[starcoin.starcoin_types.Script, starcoin.starcoin_types.Package] [source]¶
- starcoin.sdk.utils.public_key_bytes(public_key: cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey) bytes [source]¶
convert cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey into bytes
- starcoin.sdk.utils.raw_transaction_signing_msg(txn: starcoin.starcoin_types.RawTransaction) bytes [source]¶
create signing message from given starcoin_types.RawTransaction
- starcoin.sdk.utils.sub_address(addr: Union[str, bytes]) bytes [source]¶
convert hex-encoded sub-address into bytes
This function validates bytes length, and raises InvalidSubAddressError if length does not match sub-address length (8 bytes)
- starcoin.sdk.utils.transaction_hash(txn: starcoin.starcoin_types.SignedUserTransaction) str [source]¶
create transaction hash from given starcoin_types.SignedTransaction
- starcoin.sdk.utils.type_tag_to_str(code: starcoin.starcoin_types.TypeTag) str [source]¶
converts currency code TypeTag into string
- starcoin.sdk.utils.verify_signed_message(signed_message_hex: str) starcoin.starcoin_types.SignedMessage [source]¶