Blockchain core¶
Transaction class¶
-
class
dposlib.blockchain.Transaction(*args, **kwargs)[source]¶ A python
dictthat implements all the necessities to manually generate valid transactions.-
feeExcluded()[source]¶ Arrange
amountandfeevalues so the totalsatoshiflow is the desired spent plus the fee.
-
feeIncluded()[source]¶ Arrange
amountandfeevalues so the totalsatoshiflow is the desired spent.
-
finalize(secret=None, secondSecret=None, fee=None, fee_included=False)[source]¶ Finalize a transaction by setting
fee, signatures andid.Parameters: - secret (
str) – passphrase - secondSecret (
str) – second passphrase - fee (
int) – manually set fee value insatoshi - fee_included (
bool) – seefeeIncluded()feeExcluded()
- secret (
-
link(secret=None, secondSecret=None)[source]¶ Save public and private keys derived from secrets. This is equivalent to wallet login. it limits number of secret keyboard entries.
Parameters: - secret (
str) – passphrase - secondSecret (
str) – second passphrase
- secret (
-
multiSignWithKey(privateKey)[source]¶ Add a signature in
signaturesfield according to given index and privateKey.Parameters: privateKey ( str) – private key as hex string
-
multiSignWithSecret(secret)[source]¶ Add a signature in
signaturesfield.Parameters: - index (
int) – signature index - secret (
str) – passphrase
- index (
-
static
setDynamicFee(value='minFee')¶ Activate and configure dynamic fees parameters. Value can be either an integer defining the fee multiplier constant or a string defining the fee level to use acccording to the 30-days-average. possible values are
avgFeeminFee(default) andmaxFee.Parameters: value ( strorint) – constant or fee multiplier
-
setFee(value=None)[source]¶ Set
feefield manually or according to inner parameters.Parameters: value ( int) – fee value instatoshito set manually
-
static
setStaticFee()¶ Deactivate dynamic fees.
-
signSign()[source]¶ Generate the
signSignaturefield. Transaction have to be signed and second private key have to be set first. Seelink().
-
signSignWithKey(secondPrivateKey)[source]¶ Generate the
signSignaturefield using second private key. It is stored tillunlink()is called.Parameters: secondPrivateKey ( str) – second private key as hex string
-
signSignWithSecondSecret(secondSecret)[source]¶ Generate the
signSignaturefield using second passphrase. The associated second public and private keys are stored tillunlink()is called.Parameters: secondSecret ( str) – second passphrase
-
signWithKeys(publicKey, privateKey)[source]¶ Generate the
signaturefield using public and private keys. They are tillunlink()is called.Parameters: - publicKey (
str) – public key as hex string - privateKey (
str) – private key as hex string
- publicKey (
-
signWithSecret(secret)[source]¶ Generate the
signaturefield using passphrase. The associated public and private keys are stored tillunlink()is called.Parameters: secret ( str) – passphrase
-
static
useDynamicFee(value='minFee')[source]¶ Activate and configure dynamic fees parameters. Value can be either an integer defining the fee multiplier constant or a string defining the fee level to use acccording to the 30-days-average. possible values are
avgFeeminFee(default) andmaxFee.Parameters: value ( strorint) – constant or fee multiplier
-
Crypto utils¶
-
dposlib.ark.crypto.checkTransaction(tx, secondPublicKey=None, multiPublicKeys=[])[source]¶ Verify transaction validity.
Parameters: - tx (
dictorTransaction) – transaction object - secondPublicKey (
str) – second public key to use if needed - multiPublicKeys (
list) – owners public keys (sorted according to associated type-4-tx asset)
Returns: true if transaction is valid
Return type: bool- tx (
-
dposlib.ark.crypto.getAddress(publicKey, marker=None)[source]¶ Compute ARK address from publicKey.
Parameters: - publicKey (
str) – public key - marker (
int) – network marker (optional)
Returns: the address
Return type: str- publicKey (
-
dposlib.ark.crypto.getAddressFromSecret(secret, marker=None)[source]¶ Compute ARK address from secret.
Parameters: - secret (
str) – secret string - marker (
int) – network marker (optional)
Returns: the address
Return type: str- secret (
-
dposlib.ark.crypto.getBytes(tx, **options)[source]¶ Hash transaction.
Parameters: tx (
dictorTransaction) – transaction objectKeyword Arguments: - exclude_sig (
bool) – exclude signature during tx serialization [defalut: True] - exclude_multi_sig (
bool) – exclude signatures during tx serialization [defalut: True] - exclude_second_sig (
bool) – exclude second signatures during tx serialization [defalut: True]
Returns: bytes sequence
Return type: bytes- exclude_sig (
-
dposlib.ark.crypto.getId(tx)[source]¶ Generate transaction id.
Parameters: tx ( dictorTransaction) – transaction objectReturns: id as hex string Return type: str
-
dposlib.ark.crypto.getIdFromBytes(data)[source]¶ Generate data id.
Parameters: data ( bytes) – data as bytes sequenceReturns: id as hex string Return type: str
-
dposlib.ark.crypto.getKeys(secret)[source]¶ Generate keyring containing secp256k1 keys-apir and wallet import format (WIF).
Parameters: secret ( str,bytesorint) – anything that could issue a private key on secp256k1 curveReturns: public, private and WIF keys Return type: dict
-
dposlib.ark.crypto.getMultiSignaturePublicKey(minimum, *publicKeys)[source]¶ Compute ARK multi signature public key according to ARK AIP #18.
Parameters: - minimum (
int) – minimum signature required - publicKeys (
list of str) – public key list
Returns: the multisignature public key
Return type: str- minimum (
-
dposlib.ark.crypto.getSignature(tx, privateKey, **options)[source]¶ Generate transaction signature using private key.
Parameters: - tx (
dictorTransaction) – transaction description - privateKey (
str) – private key as hex string
Keyword Arguments: - exclude_sig (
bool) – exclude signature during tx serialization [defalut: True] - exclude_multi_sig (
bool) – exclude signatures during tx serialization [defalut: True] - exclude_second_sig (
bool) – exclude second signatures during tx serialization [defalut: True]
Returns: signature
Return type: str- tx (
-
dposlib.ark.crypto.getSignatureFromBytes(data, privateKey)[source]¶ Generate signature from data using private key.
Parameters: - data (
bytes) – bytes sequence - privateKey (
str) – private key as hex string
Returns: signature as hex string
Return type: str- data (
-
dposlib.ark.crypto.getWIF(seed)[source]¶ Compute WIF address from seed.
Parameters: seed ( bytes) – a sha256 sequence bytesReturns: WIF address Return type: str
-
dposlib.ark.crypto.serialize(tx, version=None, **options)[source]¶ Serialize transaction.
Parameters: tx ( dictorTransaction) – transaction objectReturns: bytes sequence Return type: bytes
-
dposlib.ark.crypto.verifySignature(value, publicKey, signature)[source]¶ Verify signature.
Parameters: - value (
str) – value as hex string - publicKey (
str) – public key as hex string - signature (
str) – signature as hex string
Returns: true if signature matches the public key
Return type: bool- value (
-
dposlib.ark.crypto.verifySignatureFromBytes(data, publicKey, signature)[source]¶ Verify signature.
Parameters: - data (
bytes) – data - publicKey (
str) – public key as hex string - signature (
str) – signature as hex string
Returns: true if signature matches the public key
Return type: bool- data (
Signature utils¶
Advanced signature manipulation. It is the recomended module to manually issue signatures for ark blockchain and forks.
- Variables:
privateKey(str): hexlified private keypublicKey(str): hexlified compressed - encoded public keymessage(str): message to sign as string
-
class
dposlib.ark.sig.Signature(*rs)[source]¶ -
static
b410_schnorr_sign(message, privateKey)[source]¶ Generate message signature according to Bcrypto 4.10 schnorr scheme.
Parameters: - message (
str) – message to verify - privateKey (
str) – private key
Returns: signature
Return type: - message (
-
b410_schnorr_verify(message, publicKey)[source]¶ Check if public key match message signature according to Bcrypto 4.10 schnorr scheme.
Parameters: - message (
str) – message to verify - publicKey (
str) – public key
Returns: True if match
Return type: bool- message (
-
der¶ Return DER encoded signature as bytes sequence
-
static
ecdsa_rfc6979_sign(message, privateKey, canonical=True)[source]¶ Generate message signature according to
ECDSAscheme using a deterministic nonce (RFC-6976).Parameters: - message (
str) – message to verify - privateKey (
str) – private key - canonical (
bool) – canonalize signature
Returns: signature
Return type: - message (
-
static
ecdsa_sign(message, privateKey, canonical=True)[source]¶ Generate message signature according to
ECDSAscheme using a random nonce.Parameters: - message (
str) – message to verify - privateKey (
str) – private key - canonical (
bool) – canonalize signature
Returns: signature
Return type: - message (
-
ecdsa_verify(message, publicKey)[source]¶ Check if public key match message signature according to
ECDSAscheme.Parameters: - message (
str) – message to verify - publicKey (
str) – public key
Returns: True if match
Return type: bool- message (
-
static
from_der(der)[source]¶ Decode signature from DER encoded bytes sequence.
Parameters: der ( bytes) – encoded signatureReturns: signature Return type: Signature
-
static
from_raw(raw)[source]¶ Decode signature from RAW encoded bytes sequence.
Parameters: raw ( bytes) – encoded signatureReturns: signature Return type: Signature
-
r¶ Signature part #1
-
raw¶ Return RAW Encode signature as bytes sequence
-
s¶ Signature part #2
-
static
schnorr_sign(message, privateKey)[source]¶ Generate message signature according to BIP schnorr scheme.
Parameters: - message (
str) – message to verify - privateKey (
str) – private key
Returns: signature
Return type: - message (
-
schnorr_verify(message, publicKey)[source]¶ Check if public key match message signature according to BIP schnorr scheme.
Parameters: - message (
str) – message to verify - publicKey (
str) – public key
Returns: True if match
Return type: bool- message (
-
static
Transaction builders¶
-
dposlib.ark.v2.transfer(amount, address, vendorField=None, expiration=0)[source]¶ Build a transfer transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - amount (
float) – transaction amount in ark - address (
str) – valid recipient address - vendorField (
str) – vendor field message - expiration (
float) – time of persistance in hour
Returns: transaction object
Return type: - amount (
-
dposlib.ark.v2.registerSecondSecret(secondSecret)[source]¶ Build a second secret registration transaction.
Parameters: secondSecret ( str) – passphraseReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.registerSecondPublicKey(secondPublicKey)[source]¶ Build a second secret registration transaction.
Note
You must own the secret issuing secondPublicKey
Parameters: secondPublicKey ( str) – public key as hex stringReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.registerAsDelegate(username)[source]¶ Build a delegate registration transaction.
Parameters: username ( str) – delegate usernameReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.upVote(*usernames)[source]¶ Build an upvote transaction.
Parameters: usernames ( iterable) – delegate usernames asstriterableReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.downVote(*usernames)[source]¶ Build a downvote transaction.
Parameters: usernames ( iterable) – delegate usernames asstriterableReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.registerMultiSignature(minSig, *publicKeys)[source]¶ Build a multisignature registration transaction.
Parameters: - minSig (
int) – minimum signature required - publicKeys (
list of str) – public key list
Returns: transaction object
Return type: - minSig (
-
dposlib.ark.v2.registerIpfs(ipfs)[source]¶ Build an IPFS registration transaction.
Parameters: ipfs ( str) – ipfs DAGReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.multiPayment(*pairs, **kwargs)[source]¶ Build multi-payment transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - pairs (
iterable) – recipient-amount pair iterable - vendorField (
str) – vendor field message
Returns: transaction object
Return type: - pairs (
-
dposlib.ark.v2.delegateResignation()[source]¶ Build a delegate resignation transaction.
Returns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.htlcSecret(secret)[source]¶ Compute an HTLC secret hex string from passphrase.
Parameters: secret ( str) – passphraseReturns: transaction object Return type: dposlib.blockchain.Transaction
-
dposlib.ark.v2.htlcLock(amount, address, secret, expiration=24, vendorField=None)[source]¶ Build an HTLC lock transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - amount (
float) – transaction amount in ark - address (
str) – valid recipient address - secret (
str) – lock passphrase - expiration (
float) – transaction validity in hour - vendorField (
str) – vendor field message
Returns: transaction object
Return type: - amount (
-
dposlib.ark.v2.htlcClaim(txid, secret)[source]¶ Build an HTLC claim transaction.
Parameters: - txid (
str) – htlc lock transaction id - secret (
str) – passphrase used by htlc lock transaction
Returns: transaction object
Return type: - txid (
-
dposlib.ark.v2.htlcRefund(txid)[source]¶ Build an HTLC refund transaction.
Parameters: txid ( str) – htlc lock transaction idReturns: transaction object Return type: dposlib.blockchain.Transaction