Blockchain core

Transaction class

class dposlib.blockchain.Transaction(*args, **kwargs)[source]

A python dict that implements all the necessities to manually generate valid transactions.

dump()[source]

Dumps transaction in registry.

feeExcluded()[source]

Arrange amount and fee values so the total satoshi flow is the desired spent plus the fee.

feeIncluded()[source]

Arrange amount and fee values so the total satoshi flow is the desired spent.

finalize(secret=None, secondSecret=None, fee=None, fee_included=False)[source]

Finalize a transaction by setting fee, signatures and id.

Parameters:
  • secret (str) – passphrase
  • secondSecret (str) – second passphrase
  • fee (int) – manually set fee value in satoshi
  • fee_included (bool) – see feeIncluded() feeExcluded()
identify()[source]

Generate the id field. Transaction have to be signed.

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
load(txid)[source]

Loads the transaction identified by txid from registry.

multiSignWithKey(privateKey)[source]

Add a signature in signatures field according to given index and privateKey.

Parameters:privateKey (str) – private key as hex string
multiSignWithSecret(secret)[source]

Add a signature in signatures field.

Parameters:
  • index (int) – signature index
  • secret (str) – passphrase
path()[source]

Return current registry path.

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 avgFee minFee (default) and maxFee.

Parameters:value (str or int) – constant or fee multiplier
setFee(value=None)[source]

Set fee field manually or according to inner parameters.

Parameters:value (int) – fee value in statoshi to set manually
static setStaticFee()

Deactivate dynamic fees.

sign()[source]

Generate the signature field. Private key have to be set first. See link().

signSign()[source]

Generate the signSignature field. Transaction have to be signed and second private key have to be set first. See link().

signSignWithKey(secondPrivateKey)[source]

Generate the signSignature field using second private key. It is stored till unlink() is called.

Parameters:secondPrivateKey (str) – second private key as hex string
signSignWithSecondSecret(secondSecret)[source]

Generate the signSignature field using second passphrase. The associated second public and private keys are stored till unlink() is called.

Parameters:secondSecret (str) – second passphrase
signWithKeys(publicKey, privateKey)[source]

Generate the signature field using public and private keys. They are till unlink() is called.

Parameters:
  • publicKey (str) – public key as hex string
  • privateKey (str) – private key as hex string
signWithSecret(secret)[source]

Generate the signature field using passphrase. The associated public and private keys are stored till unlink() 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 avgFee minFee (default) and maxFee.

Parameters:value (str or int) – constant or fee multiplier
static useStaticFee()[source]

Deactivate dynamic fees.

Crypto utils

dposlib.ark.crypto.checkTransaction(tx, secondPublicKey=None, multiPublicKeys=[])[source]

Verify transaction validity.

Parameters:
  • tx (dict or Transaction) – 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

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

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

dposlib.ark.crypto.getBytes(tx, **options)[source]

Hash transaction.

Parameters:

tx (dict or Transaction) – transaction object

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:

bytes sequence

Return type:

bytes

dposlib.ark.crypto.getId(tx)[source]

Generate transaction id.

Parameters:tx (dict or Transaction) – transaction object
Returns:id as hex string
Return type:str
dposlib.ark.crypto.getIdFromBytes(data)[source]

Generate data id.

Parameters:data (bytes) – data as bytes sequence
Returns: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, bytes or int) – anything that could issue a private key on secp256k1 curve
Returns: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

dposlib.ark.crypto.getSignature(tx, privateKey, **options)[source]

Generate transaction signature using private key.

Parameters:
  • tx (dict or Transaction) – 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

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

dposlib.ark.crypto.getWIF(seed)[source]

Compute WIF address from seed.

Parameters:seed (bytes) – a sha256 sequence bytes
Returns:WIF address
Return type:str
dposlib.ark.crypto.serialize(tx, version=None, **options)[source]

Serialize transaction.

Parameters:tx (dict or Transaction) – transaction object
Returns: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

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

dposlib.ark.crypto.wifSignature(tx, wif)[source]

Generate transaction signature using private key.

Parameters:
  • tx (dict or Transaction) – transaction description
  • wif (str) – wif key
Returns:

signature

Return type:

str

dposlib.ark.crypto.wifSignatureFromBytes(data, wif)[source]

Generate signature from data using WIF key.

Parameters:
  • data (bytes) – bytes sequence
  • wif (str) – wif key
Returns:

signature

Return type:

str

Signature utils

Advanced signature manipulation. It is the recomended module to manually issue signatures for ark blockchain and forks.

Variables:
  • privateKey (str): hexlified private key
  • publicKey (str): hexlified compressed - encoded public key
  • message (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:

Signature

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

der

Return DER encoded signature as bytes sequence

static ecdsa_rfc6979_sign(message, privateKey, canonical=True)[source]

Generate message signature according to ECDSA scheme using a deterministic nonce (RFC-6976).

Parameters:
  • message (str) – message to verify
  • privateKey (str) – private key
  • canonical (bool) – canonalize signature
Returns:

signature

Return type:

Signature

static ecdsa_sign(message, privateKey, canonical=True)[source]

Generate message signature according to ECDSA scheme using a random nonce.

Parameters:
  • message (str) – message to verify
  • privateKey (str) – private key
  • canonical (bool) – canonalize signature
Returns:

signature

Return type:

Signature

ecdsa_verify(message, publicKey)[source]

Check if public key match message signature according to ECDSA scheme.

Parameters:
  • message (str) – message to verify
  • publicKey (str) – public key
Returns:

True if match

Return type:

bool

static from_der(der)[source]

Decode signature from DER encoded bytes sequence.

Parameters:der (bytes) – encoded signature
Returns:signature
Return type:Signature
static from_raw(raw)[source]

Decode signature from RAW encoded bytes sequence.

Parameters:raw (bytes) – encoded signature
Returns: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:

Signature

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

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:

dposlib.blockchain.Transaction

dposlib.ark.v2.registerSecondSecret(secondSecret)[source]

Build a second secret registration transaction.

Parameters:secondSecret (str) – passphrase
Returns: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 string
Returns:transaction object
Return type:dposlib.blockchain.Transaction
dposlib.ark.v2.registerAsDelegate(username)[source]

Build a delegate registration transaction.

Parameters:username (str) – delegate username
Returns:transaction object
Return type:dposlib.blockchain.Transaction
dposlib.ark.v2.upVote(*usernames)[source]

Build an upvote transaction.

Parameters:usernames (iterable) – delegate usernames as str iterable
Returns:transaction object
Return type:dposlib.blockchain.Transaction
dposlib.ark.v2.downVote(*usernames)[source]

Build a downvote transaction.

Parameters:usernames (iterable) – delegate usernames as str iterable
Returns: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:

dposlib.blockchain.Transaction

dposlib.ark.v2.registerIpfs(ipfs)[source]

Build an IPFS registration transaction.

Parameters:ipfs (str) – ipfs DAG
Returns: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:

dposlib.blockchain.Transaction

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) – passphrase
Returns: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:

dposlib.blockchain.Transaction

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:

dposlib.blockchain.Transaction

dposlib.ark.v2.htlcRefund(txid)[source]

Build an HTLC refund transaction.

Parameters:txid (str) – htlc lock transaction id
Returns:transaction object
Return type:dposlib.blockchain.Transaction