API Documentation

  • ARK C++ Crypto v1.1.0

Ark::Crypto::Configuration

Configuration()

1// default: Devnet
2 
3#include "common/configuration.hpp"
4 
5Ark::Crypto::Configuration config;
1#include "common/configuration.hpp"
2 
3Ark::Crypto::Configuration config(const Network &network);
1#include "common/configuration.hpp"
2 
3Ark::Crypto::Configuration config(const FeePolicy &policy);
1#include "common/configuration.hpp"
2 
3Ark::Crypto::Configuration config(const Network &network, const FeePolicy &policy);

Create a network configuration

Parameters

Type Name Required Description
const Network& network no Network configuration
const FeePolicy& policy no Fee Policy for a the provided network

Return Value

void

getFee()

1// Default: Devnet
2 
3#include "common/configuration.hpp"
4 
5Ark::Crypto::Configuration config;
6uint64_t fee = config.getFee(uint16_t type);

Get a fee for a given transaction type

Parameters

Type Name Required Description
uint16_t type Yes Transaction type for which we wish to get a fee

Return Value

uint64_t

setFee()

1Ark::Crypto::Configuration config;
2config.setFee(uint16_t type, uint64_t fee);

Set a fee

Parameters

Type Name Required Description
uint16_t type Yes Transaction type for which we wish to set a fee
uint64_t fee Yes Fee for a given transaction type

Return Value

void

setNetwork()

1Ark::Crypto::Configuration config;
2config.setNetwork(const Ark::Crypto::Network &network);

Set what network you want to use in the crypto library

Parameters

Type Name Required Description
Network& network Yes Testnet, Devnet, Mainnet, Custom

Return Value

void

getNetwork()

1Ark::Crypto::Configuration config;
2config.getNetwork();

Get settings for a selected network, default network is devnet

Return Value

Ark::Crypto::Network

Ark::Crypto::Message

1class Message {
2 public:
3 std::string message;
4 std::array<uint8_t, 32> publicKey;
5 std::vector<uint8_t> signature;
6};

Message data structure

Message()

1#include "crypto/message.hpp"
2 
3Ark::Crypto::Utils::Message message;

Create a new empty message instance to be created and signed Message()

1#include "crypto/message.hpp"
2 
3Ark::Crypto::Utils::Message message(std::string message, const uint8_t *publicKeyBytes, const uint8_t *signature);

Create a new message instance ready for verification

Parameters

Type Name Required Description
std::string message Yes Message to sign
const uint8_t* publicKeyBytes Yes Public key bytes (uint8_t[33])
const uint8_t* signature Yes Signature bytes (uint8_t[32])

sign()

1#include "crypto/message.hpp"
2 
3Ark::Crypto::Message message;
4 
5bool isValidMessage = message.sign(const std::string& message, const std::string &passphrase);

Sign a message using the given passphrase.

Parameters

Type Name Required Description
const std::string& message Yes Message
const std::string& passphrase Yes Passphrase

Return Value

bool

verify()

1#include "crypto/message.hpp"
2 
3bool isValidMessage = message.verify();

Verify the message contents

Return Value

bool

toMap()

1#include "crypto/message.hpp"
2 
3std::map<std::string, std::string> messageMap = message.toMap();

Convert the message to its string-map representation

Return Value

std::map<std::string, std::string>

toJson()

1#include "crypto/message.hpp"
2 
3std::string messageJsonString = message.toJson();

Convert the message to its JSON representation

Return Value

std::string

Ark::Crypto::Slot

epoch()

1#include "crypto/slot.hpp"
2 
3uint64_t epoch = Ark::Crypto::Slot::epoch(const Ark::Crypto::Network &network);

Get the network start epoch.

Parameters

Type Name Required Description
const Network& network Yes Network

Return Value

uint64_t

time()

1#include "crypto/slot.hpp"
2 
3uint64_t time = Ark::Crypto::Slot::time(const Ark::Crypto::Network &network)

Get the time diff between now and network start.

Parameters

Type Name Required Description
const Network& network Yes Network

Return Value

uint64_t

Ark::Crypto::Identities::Address

Address() (const char*)

1#include "identities/address.hpp"
2 
3Ark::Crypto::Identities::Address address(const char *addressString);

Constructor of the Address class.

Parameters

Type Name Required Description
const char* addressString Yes Valid address string

Address() (PubKeyHash, uint8_t)

1#include "identities/address.hpp"
2 
3Ark::Crypto::Identities::Address address(const PubkeyHash &pubkeyHash, uint8_t version);

Constructor of the Address class.

Parameters

Type Name Required Description
const PubkeyHash& pubkeyHash Yes Valid PubkeyHash (std::array)
uint8_t version Yes Network version-byte

version()

1#include "identities/address.hpp"
2 
3Ark::Crypto::Identities::Address address(const char *addressString);
4uint8_t version = address.version()

Get the network version of an address.

Return Value

uint8_t

toBytes()

1#include "identities/address.hpp"
2 
3Ark::Crypto::Identities::Address address(const char *addressString);
4const auto pubKeyHash = address.toBytes()

Convert the address to its pubKey hash.

Return Value

PubkeyHash

toString()

1#include "identities/address.hpp"
2 
3Ark::Crypto::Identities::Address address(const PubkeyHash &pubkeyHash, uint8_t version);
4std::string addressString = address.toString();

Convert the address to its string representation.

Return Value

std::string

fromPublicKey()

1#include "identities/address.hpp"
2 
3const auto address = Ark::Crypto::Identities::Address::fromPublicKey(const uint8_t *publicKeyBytes, uint8_t version);

Derive the address from the given public key.

Parameters

Type Name Required Description
const uint8_t* publicKeyBytes Yes Public key bytes (uint8_t[33])
uint8_t version Yes Version of the network

Return Value

Ark::Crypto::Identities::Address

fromPrivateKey()

1#include "identities/address.hpp"
2 
3const auto address = Ark::Crypto::Identities::Address::fromPrivateKey(const uint8_t *privateKeyBytes, uint8_t version);

Derive the address from the given private key.

Parameters

Type Name Required Description
const uint8_t* privateKeyBytes Yes Private key bytes (uint8_t[32])
uint8_t version Yes Version of the network

Return Value

Ark::Crypto::Identities::Address

fromPassphrase()

1#include "identities/address.hpp"
2 
3const auto address = Ark::Crypto::Identities::Address::fromPassphrase(const char *passphrase, uint8_t version);

Derive the address from the given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes 12-word passphrase
uint8_t version Yes Version of the network

Return Value

Ark::Crypto::Identities::Address

validate()

1#include "identities/address.hpp"
2 
3bool isValidAddress = Ark::Crypto::Identities::Address::validate(const Address &address, uint8_t version);

Validate the given address.

Parameters

Type Name Required Description
const Address& address Yes Address to validate
uint8_t networkVersion Yes Version of the network

Return Value

bool

validate() (const char*, uint8_t)

1#include "identities/address.hpp"
2 
3bool Ark::Crypto::Identities::Address::validate(const char *const addressStr, uint8_t networkVersion);

Validate the given Address string to the network version.

Parameters

Type Name Required Description
const char* addressStr Yes Address to validate
uint8_t networkVersion Yes Version of the network

Return Value

bool

validate() (uint8_t*, uint8_t)

1#include "identities/address.hpp"
2 
3bool Ark::Crypto::Identities::Address::validate(const uint8_t *addressBytes, uint8_t networkVersion);

Validate the given Address bytes to the network version.

Parameters

Type Name Required Description
uint8_t* addressBytes Yes Address to validate
uint8_t networkVersion Yes Version of the network

Return Value

bool

Ark::Crypto::Identities::Keys

1struct KeyPair {
2 std::array<uint8_t, 32> privateKey { };
3 std::array<uint8_t, 33> publicKey { };
4};

fromPassphrase()

1#include "identities/keys.hpp"
2 
3const KeyPair keys = Ark::Crypto::Identities::PrivateKey::fromPassphrase(const char *passphrase);

Create a key-pair instance from the given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes Passphrase

Return Value

Ark::Crypto::KeyPair

fromPrivateKey()

1#include "identities/keys.hpp"
2 
3const KeyPair keys = Ark::Crypto::Identities::PrivateKey::fromPrivateKey(const uint8_t *privateKeyBytes);

Create a key-pair instance from privateKey bytes.

Parameters

Type Name Required Description
const uint8_t* privateKeyBytes Yes Private Key bytes (uint8_t[32])

Return Value

Ark::Crypto::KeyPair

fromWif()

1#include "identities/keys.hpp"
2 
3const KeyPair keys = Ark::Crypto::Identities::PrivateKey::fromWif(const char *wif);

Create a key-pair instance from privateKey bytes.

Parameters

Type Name Required Description
const char* wif Yes WIF string

Return Value

Ark::Crypto::KeyPair

PrivateKey::fromPassphrase()

1#include "identities/keys.hpp"
2 
3const PrivateKeyBytes privateKeyBytes = Ark::Crypto::Identities::Keys::PrivateKey::fromPassphrase(const char *passphrase);

Generate PrivateKey bytes from a given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes Passphrase

Return Value

Ark::Crypto::PrivateKeyBytes

PrivateKey::fromWif()

1#include "identities/keys.hpp"
2 
3const PrivateKeyBytes privateKeyBytes = Ark::Crypto::Identities::Keys::PrivateKey::fromWif(const char *wif, uint8_t *outVersion);

Generate PrivateKey bytes and the network version from a given wif string.

Parameters

Type Name Required Description
const char* wif Yes Wif string
uint8_t* outVersion Yes output Wif version

Return Value

Ark::Crypto::PrivateKeyBytes

PublicKey::fromPrivateKey()

1#include "identities/keys.hpp"
2 
3const PublicKeyBytes publicKeyBytes = Ark::Crypto::Identities::Keys::PublicKey::fromPrivatekey(const uint8_t *privateKeyBytes);

Generate PublicKey bytes PrivateKey bytes.

Parameters

Type Name Required Description
const uint8_t* privateKeyBytes Yes Private Key bytes (uint8_t[32])

Return Value

Ark::Crypto::PublicKeyBytes

Ark::Crypto::Identities::PrivateKey

PrivateKey()

1#include "identities/privatekey.hpp"
2 
3Ark::Crypto::Identities::PrivateKey privateKey(const PrivateKeyBytes &privateKeyBytes);

Constructor of the Private Key class.

Parameters

Type Name Required Description
const PrivateKeyBytes& privateKeyBytes Yes Private Key (std::array)

toBytes()

1#include "identities/privatekey.hpp"
2 
3Ark::Crypto::Identities::Privatekey privateKey(const PrivateKeyBytes &privateKeyBytes);
4const auto privateKeyBytes = privateKey.toBytes()

Convert the private key to its bytes representation.

Return Value

PrivateKeyBytes

toString()

1#include "identities/privatekey.hpp"
2 
3Ark::Crypto::Identities::Privatekey privateKey(const PrivateKeyBytes &privateKeyBytes);
4const auto privateKeyString = privateKey.toString()

Convert the private key to its string representation.

Return Value

std::string

fromPassphrase()

1#include "identities/privatekey.hpp"
2 
3const auto privateKey = Ark::Crypto::Identities::PrivateKey::fromPassphrase(const char *passphrase);

Derive the private key for the given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes Passphrase

Return Value

Ark::Crypto::Identities::PrivateKey

fromHex()

1#include "identities/privatekey.hpp"
2 
3const auto privateKey = Ark::Crypto::Identities::PrivateKey::fromHex(const char *privateKeyHex);

Create a private key instance from a hex string.

Parameters

Type Name Required Description
const char* privateKeyHex Yes Private key hex-string

Return Value

Ark::Crypto::Identities::PrivateKey

Ark::Crypto::Identities::PublicKey

PublicKey()

1#include "identities/publickey.hpp"
2 
3Ark::Crypto::Identities::PublicKey publicKey(const PublicKeyBytes &publicKeyBytes);

Constructor of the Public Key class.

Parameters

Type Name Required Description
const PublicKeyBytes& publicKeyBytes Yes Public Key bytes (std::array)

toBytes()

1#include "identities/publickey.hpp"
2 
3const PublicKeyBytes publicKeyBytes = publicKey.toBytes();

Convert the public key to its byte representation.

Return Value

Ark::Crypto:PublicKeyBytes

toString()

1#include "identities/publickey.hpp"
2 
3std::string publicKeyString = publicKey::toString();

Convert the public key to its string representation.

Return Value

std::string

fromPassphrase()

1#include "identities/publickey.hpp"
2 
3const auto publicKey = Ark::Crypto::Identities::PublicKey::fromPassphrase(const char *passphrase);

Derive the public from the given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes Passphrase

Return Value

Ark::Crypto::Identities::PublicKey

fromHex()

1#include "identities/publickey.hpp"
2 
3const auto publicKey = Ark::Crypto::Identities::PublicKey::fromHex(const char *publicKeyHex);

Create a public key instance from a hex string.

Parameters

Type Name Required Description
const char* publicKeyHex Yes Public key hex-string

Return Value

Ark::Crypto::Identities::PublicKey

Ark::Crypto::Identities::Wif

Wif() (PrivateKeyBytes, uint8_t)

1#include "identities/wif.hpp"
2 
3Ark::Crypto::Identities::Wif wif(const PrivateKeyBytes &privateKeyBytes, uint8_t version);

Constructor of the Wif class.

Parameters

Type Name Required Description
const PrivateKeyBytes& privateKeyBytes Yes Private Key bytes (std::array)
uint8_t version Yes Network Wif version

Wif() (const char*)

1#include "identities/wif.hpp"
2 
3Ark::Crypto::Identities::Wif wif(const char *wif);

Constructor of the Wif class.

Parameters

Type Name Required Description
const char* wif Yes Network WIF string

version()

1#include "identities/wif.hpp"
2 
3const uint8_t version = wif.version();

Get the network version of the Wif.

Return Value

uint8_t

toBytes()

1#include "identities/wif.hpp"
2 
3const PrivateKeyBytes privateKeyBytes = wif.toBytes();

Convert the Wif to a PrivateKeyBytes representation.

Return Value

Ark::Crypto::PrivateKeyBytes

toString()

1#include "identities/wif.hpp"
2 
3std::string wifString = wif.toString();

Convert the Wif to its string representation.

Return Value

std::string

fromPassphrase()

1#include "identities/wif.hpp"
2 
3const auto wif = Ark::Crypto::Identities::Wif::fromPassphrase(const char *passphrase, uint8_t version);

Derive the Wif from the given passphrase.

Parameters

Type Name Required Description
const char* passphrase Yes Passphrase
uint8_t version Yes Network WIF version

Return Value

Ark::Crypto::Identities::Wif

Ark::Crypto::Network

1struct Ark::Crypto::Network {
2 std::string nethash;
3 uint8_t slip44;
4 uint8_t wif;
5 uint8_t version;
6 std::string epoch;
7};

Network data structure

Network()

1#include "common/network.hpp"
2 
3const Ark::Crypto::Network CustomNetwork {
4 "16c891512149d6d3ff1b70e65900936140bf853a4ae79b5515157981dcc706df",
5 1, 0x53, 0xaa,
6 "2019-04-12T13:00:00.000Z"
7};

Create a network instance

Parameters

Type Name Required Description
std::string nethash Yes Nethash
uint8_t slip44 Yes Slip44 index
uint8_t wif Yes Wif version
uint8_t version Yes Network version
std::string epoch Yes Network epoch

Ark::Crypto::transactions::Builder

Transfer()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::Transfer(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .vendorField(const std::string& vendorField)
13 .vendorFieldHex(const uint8_t *vendorField, const size_t &length)
14 
15 .amount(uint64_t amount)
16 .expiration(uint32_t expiration)
17 .recipientId(const uint8_t *addressHash)
18 
19 .signature(const uint8_t *signature, const size_t &length)
20 .secondSignature(const uint8_t *secondSignature, const size_t &length)
21 
22 .sign(const std::string& passphrase)
23 .secondSign(const std::string& secondPassphrase)
24 
25 .build();

Build a Transfer Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const std::string& vendorField No Transaction vendorfield
const uint8_t*, const size_t& vendorFieldHex No Transaction vendorfield hex
uint64_t amount Yes Transfer amount
uint32_t expiration Yes Transfer expiration
const uint8_t* recipientId Yes Transfer recipient address hash (uint8_t[1 + 20])
const uint8_t*, const size_t& signature¹ No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

SecondSignature()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::SecondSignature(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .publicKey(const uint8_t *secondPublicKey)
13 
14 .signature(const uint8_t *signature, const size_t &length)
15 .secondSignature(const uint8_t *secondSignature, const size_t &length)
16 
17 .sign(const std::string& passphrase)
18 
19 .build();

Build a Second Signature Registration Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t* publicKey Yes Second PublicKey (uint8_t[33])
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

DelegateRegistration()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::DelegateRegistration(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .username(const uint8_t *username, const size_t &length)
13 .username(const std::string &username)
14 
15 .signature(const uint8_t *signature, const size_t &length)
16 .secondSignature(const uint8_t *secondSignature, const size_t &length)
17 
18 .sign(const std::string& passphrase)
19 .secondSign(const std::string& secondPassphrase)
20 
21 .build();

Build a Delegate Registration Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t*, const size_t &length username Yes Delegate Username from bytes and length
const std::string& username Yes Delegate Username from a string
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

Vote()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::Vote(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .votes(const uint8_t *votes)
13 
14 .signature(const uint8_t *signature, const size_t &length)
15 .secondSignature(const uint8_t *secondSignature, const size_t &length)
16 
17 .sign(const std::string& passphrase)
18 .secondSign(const std::string& secondPassphrase)
19 
20 .build();

Build a Vote Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t* votes Yes Vote-bytes¹
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

¹ (uint8_t votes[] = { count,0x00(-)|0x01(+), publicKey, ..., ... }; )

Return Value

Transaction

Ipfs()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::Ipfs(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .ipfs(const uint8_t *ipfsHash, const size_t &length)
13 
14 .signature(const uint8_t *signature, const size_t &length)
15 .secondSignature(const uint8_t *secondSignature, const size_t &length)
16 
17 .sign(const std::string& passphrase)
18 .secondSign(const std::string& secondPassphrase)
19 
20 .build();

Build an Ipfs Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t*, const size_t& ipfs Yes Ipfs hash-bytes
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

MultiPayment()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::MultiPayment(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .n_payments(uint16_t n_payments)
13 .amounts(const std::vector<uint64_t> &amounts)
14 .addresses(const std::vector<std::array<uint8_t, 21> > &addresses)
15 
16 .signature(const uint8_t *signature, const size_t &length)
17 .secondSignature(const uint8_t *secondSignature, const size_t &length)
18 
19 .sign(const std::string& passphrase)
20 .secondSign(const std::string& secondPassphrase)
21 
22 .build();

Build a MultiPayment Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
uint16_t n_payments Yes Number of Payments
const std::vector amounts Yes Vector of amounts for payments[i]
const std::vector > addresses Yes Vector of Address Hashes for payments[i]¹
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

¹ (Address Hash: uint8_t[1 + 20] | { networkVersion, PubkeyHash } )

Return Value

Transaction

HtlcLock()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::HtlcLock(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .amount(uint64_t amount)
13 .secretHash(const uint8_t *secretHash)
14 .expirationType(uint8_t expirationType)
15 .expiration(uint32_t expiration)
16 .recipientId(const uint8_t *addressHash)
17 
18 .signature(const uint8_t *signature, const size_t &length)
19 .secondSignature(const uint8_t *secondSignature, const size_t &length)
20 
21 .sign(const std::string& passphrase)
22 .secondSign(const std::string& secondPassphrase)
23 
24 .build();

Build an Htlc Lock Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
uint64_t amount Yes Htlc Lock amount
const uint8_t* amount Yes Htlc Lock Secret hash (uint8_t[32])
uint8_t expirationType Yes Htlc Lock Expiration Type
uint32_t expiration Yes Htlc Lock Expiration
const uint8_t* recipientId Yes Htlc Lock recipient address hash (uint8_t[1 + 20])
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

HtlcClaim()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::HtlcClaim(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .lockTransactionId(const uint8_t *lockTransactionId)
13 .unlockSecret(const uint8_t *unlockSecret)
14 
15 .signature(const uint8_t *signature, const size_t &length)
16 .secondSignature(const uint8_t *secondSignature, const size_t &length)
17 
18 .sign(const std::string& passphrase)
19 .secondSign(const std::string& secondPassphrase)
20 
21 .build();

Build an Htlc Claim Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t* lockTransactionId Yes TransactionId of the Htlc Lock Transaction (uint8_t[32])
const uint8_t* unlockSecret Yes Htlc Claim Unlock Secret (uint8_t[32])
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

HtlcRefund()

1#include "transactions/builders/builder.hpp"
2 
3const auto transaction = builder::HtlcRefund(const Configuration &config = {})
4 .version(uint8_t version)
5 .network(uint8_t network)
6 .typeGroup(uint16_t typeGroup)
7 .type(uint16_t type)
8 .nonce(uint64_t nonce)
9 .senderPublicKey(const uint8_t *senderPublicKey)
10 .fee(uint64_t fee)
11 
12 .lockTransactionId(const uint8_t *lockTransactionId)
13 
14 .signature(const uint8_t *signature, const size_t &length)
15 .secondSignature(const uint8_t *secondSignature, const size_t &length)
16 
17 .sign(const std::string& passphrase)
18 .secondSign(const std::string& secondPassphrase)
19 
20 .build();

Build an Htlc Claim Transaction

Parameters

Type Name Required Description
uint8_t version No Transaction version
uint8_t network No Network version
uint16_t typeGroup No Transaction Type-Group
uint16_t type No Transaction Type
uint64_t nonce Yes Transaction (Sequential) Nonce
const uint8_t* senderPublicKey No Sender PublicKey
uint64_t fee No Transaction fee
const uint8_t* lockTransactionId Yes TransactionId of the Htlc Lock Transaction (uint8_t[32])
const uint8_t*, const size_t& signature No Transaction Signature
const uint8_t*, const size_t& secondSignature No Transaction Second Signature
const std::string& sign No Passphrase
const std::string& secondSign No Second passphrase
const Configuration& build Yes Finish the builder process

Return Value

Transaction

Ark::Crypto::transactions::Transaction

TransactionData()

1struct TransactionData {
2 uint8_t header { 0xff };
3 uint8_t version { 2 };
4 uint8_t network { 30 };
5 
6 uint32_t typeGroup { 1 }; // v2
7 uint16_t type { 0 }; // v1: 1 Byte | v2: 2 Bytes
8 
9 uint64_t nonce { 0 }; // v2 only
10 uint32_t timestamp { 0 }; // v1 only
11 
12 std::array<uint8_t, 33> senderPublicKey { };
13 
14 uint64_t fee { 0 };
15 
16 std::vector<uint8_t> vendorField;
17 
18 Asset asset;
19 
20 std::array<uint8_t, 32> id { };
21 std::vector<uint8_t> signature;
22 std::vector<uint8_t> secondSignature;
23};

Transaction data model

Transaction()

1class Transaction {
2 public:
3 Transaction() = default;
4 
5 std::array<uint8_t, 32> getId() const;
6 
7 bool sign(const std::string &passphrase);
8 bool secondSign(const std::string &secondPassphrase);
9 
10 bool verify() const;
11 bool secondVerify(const uint8_t *secondPublicKey) const;
12 
13 bool deserialize(const std::vector<uint8_t> &serialized);
14 std::vector<uint8_t> serialize();
15 
16 std::vector<uint8_t> toBytes(const SerializerOptions &options = { false, false }) const;
17 
18 std::map<std::string, std::string> toMap() const;
19 std::string toJson() const;
20 
21 TransactionData data;
22};

Transaction model

1Ark::Crypto::transactions::Transaction transaction;

getId()

1#include "transactions/transaction.hpp"
2 
3Hash32 txId = transaction.getId();

Convert the byte representation to a unique identifier.

Return Value

Hash32 (std::array)

sign()

1#include "transactions/transaction.hpp"
2 
3bool wasSuccessful = transaction.sign(const std::string &passphrase);

Sign the transaction using the given passphrase.

Parameters

Type Name Required Description
const std::string& passphrase Yes Passphrase

Return Value

bool

secondSign()

1#include "transactions/transaction.hpp"
2 
3bool wasSuccessful = transaction.secondSign(const std::string &secondPassphrase);

Sign the transaction using the given second passphrase.

Parameters

Type Name Required Description
const std::string& secondPassphrase Yes Second passphrase

Return Value

bool

verify()

1#include "transactions/transaction.hpp"
2 
3bool isVerified = transaction.verify();

Verify the transaction.

Return Value

bool

secondVerify()

1#include "transactions/transaction.hpp"
2 
3bool isSecondVerified = transaction.secondVerify(const uint8_t *secondPublicKey);

Verify the transaction with a second public key.

Parameters

Type Name Required Description
const uint8_t* secondPublicKey Yes Second public key bytes (uint8_t[33])

Return Value

bool

deserialize()

1#include "transactions/transaction.hpp"
2 
3bool wasDeserialized = transaction.deserialize(const std::vector<uint8_t> &serialized);

Deserialize a validly-serialized transaction byte-array

Parameters

Type Name Required Description
const std::vector& serialized Yes Serialized transaction byte-array

Return Value

bool

serialize()

1#include "transactions/transaction.hpp"
2 
3std::vector<uint8_t> serialized = transaction.serialize();

Serialize a transaction instance

Return Value

std::vector<uint8_t>

toBytes()

1#include "transactions/transaction.hpp"
2 
3std::vector<uint8_t> transaction.toBytes(const SerializerOptions &options = { false, false })

Convert the transaction to its byte representation.

Parameters

Type Name Required Description
bool skipSignature No Skip first signature
bool skipSecondSignature No Skip second signature

Return Value

std::vector<uint8_t>

toMap()

1#include "transactions/transaction.hpp"
2 
3std::map<std::string, std::string> txMap = transaction.toMap();

Convert the transaction to its string-map representation.

Return Value

std::map<std::string, std::string>

toJson()

1#include "transactions/transaction.hpp"
2 
3std::string txString = transaction.toJson();

Convert the transaction to its Json-string representation.

Return Value

std::string

Last updated 10 months ago
Edit Page
Share:
2022 © ARK.io | All Rights Reserved
An ARK.io Product