Examples
Initialization
1from crypto.transactions.builder.transfer import Transfer
The transaction object used for this section:
1tx = { 2 'version': int, 3 'network': int, 4 'type': int, 5 'timestamp': int, 6 'senderPublicKey', str 7 'fee': int, 8 'amount': int, 9 'expiration': int,10 'recipientId': str,11 'signature': str,12 'id': str13 'serialized': str,14}
Transactions
A transaction is an object specifying the transfer of funds from the sender’s wallet to the recipient’s. Each transaction must be signed by the sender’s private key to prove authenticity and origin. After broadcasting through the client SDK , a transaction is permanently incorporated in the blockchain by a Delegate Node.
Sign
The crypto SDK can sign a transaction using your private key or passphrase (from which the private key is generated). Ensure you are familiar with digital signatures before using the crypto SDKs.
For serializing and deserializing, we must require the Transaction model:
1from crypto.transactions.transaction import Transaction2 3# Serializing4transaction = Transaction(**tx)5transaction.serialize()6 7# Deserializing8transaction = Transaction()9transaction.deserialize(**tx['serialized'])
Using the Transaction builder class.
1transaction = Transfer(recipientId=str, amount=int)2transaction.schnorr_sign('seedPass')
Serialize (AIP11)
Serialization of a transaction object ensures it is compact and properly formatted to be incorporated in the ARK blockchain. If you are using the crypto SDK in combination with the public API SDK, you should not need to serialize manually.
1from crypto.transactions.serializer import Serializer2 3serialized_transaction = Serializer(tx).serialize()4 5>>> <class 'str'>
Deserialize (AIP11)
A serialized transaction may be deserialized for inspection purposes. The public API does not return serialized transactions, so you should only need to deserialize in exceptional circumstances.
1from crypto.transactions.deserializer import Deserializer2 3transaction_data = Deserializer(serialized_data).deserialize()4 5>>> <class 'crypto.transactions.transaction.Transaction'>
Message
The crypto SDK not only supports transactions but can also work with other arbitrary data (expressed as strings).
Sign
Signing a string works much like signing a transaction: in most implementations, the message is hashed, and the resulting hash is signed using the
private key
orpassphrase
.
1from crypto.utils.message import Message2 3message = Message.sign(string, 'validSeedPass')4 5>>> <class 'crypto.utils.message.Message'>
Verify
A message’s signature can easily be verified by hash, without the private key that signed the message, by using the
verify
method.
1from crypto.utils.message import Message 2 3message = Message( 4 message=str, 5 signature=str, 6 public_key=str 7) 8 9# Can also be used like this10message = Message(str, 'validSignature', 'validPublicKey')11 12message.verify()13 14>>> <class 'bool'>
Identities
The identities class allows for the creation and inspection of keyPairs from
passphrases
. Here you find vital functions when creating transactions and managing wallets.
Derive the Address from a Passphrase
1from crypto.identity.address import address_from_passphrase2 3address_from_passphrase('validSeedPass')4 5>>> <class 'str'>
Derive the Address from a Public Key
1from crypto.identity.address import address_from_public_key2 3address_from_public_key('validPublicKey')4 5>>> <class 'str'>
Derive the Address from a Private Key
1from crypto.identity.address import address_from_private_key2 3address_from_private_key('validPrivateKey')4 5>>> <class 'str'>
Validate an Address
1from crypto.identity.address import validate_address2 3validate_address('validAddress')4 5>>> <class 'bool'>
Private Key
As the name implies, private keys and passphrases are to remain private. Never store these unencrypted and minimize access to these secrets
Derive the Private Key from a Passphrase
1from crypto.identity.private_key import PrivateKey2 3private_key = PrivateKey.from_passphrase('validSeedPass').to_hex()4 5>>> <class 'str'>
Derive the Private Key Instance Object from a Hexadecimal Encoded String
1from crypto.identity.private_key import PrivateKey2 3private_key = PrivateKey.from_hex(str)4 5>>> <class 'crypto.identity.private_key.PrivateKey'>
Derive the Private Key from a WIF
1This function has not been implemented in this client library.
Public Key
Public Keys may be freely shared, and are included in transaction objects to validate the authenticity.
Derive the Public Key from a Passphrase
1from crypto.identity.public_key import PublicKey2 3public_key = PublicKey.from_passphrase('this is a top secret passphrase')4 5>>> <class 'str'>
Derive the Public Key Instance Object from a Hexadecimal Encoded String
1from crypto.identity.public_key import PublicKey2 3public_key = PublicKey.from_hex(str)4 5>>> <class 'crypto.identity.public_key.PublicKey'>
Validate a Public Key
1This function has not been implemented in this client library.
WIF
The WIF should remain secret, just like your
passphrase
andprivate key
.
Derive the WIF from a Passphrase
1from crypto.identity.wif import wif_from_passphrase2 3wif = wif_from_passphrase('validSeedPass')4 5>>> <class 'str'>