API Documentation

crypto.configuration

SetNetwork()

1func SetNetwork(network *Network)

Set what network you want to use in the crypto library

Parameters

Type Name Required Description
*Network network Yes Testnet, Devnet, Mainnet

GetNetwork()

1func GetNetwork() *Network

Get settings for a selected network, default network is devnet

Return Value

*Network

GetFee()

1func GetFee(transactionType byte) FlexToshi

Get a fee for a given transaction type

Parameters

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

Return Value

FlexToshi

SetFee()

1func SetFee(transactionType byte, value FlexToshi)

Set a fee

Parameters

Type Name Required Description
byte transactionType Yes Transaction_type for which we wish to set a fee
FlexToshi value Yes Fee for a given transaction type

crypto.address

AddressFromPassphrase()

1func AddressFromPassphrase(passphrase string) (string, error)

Derive the address from the given passphrase.

Parameters

Type Name Required Description
string passphrase Yes Passphrase

Return Value

(string, error)

AddressToBytes()

1func AddressToBytes(address string) ([]byte, error)

Derive the given address to its bytes representation.

Parameters

Type Name Required Description
string address Yes address

Return Value

([]byte, error)

validate()

1func ValidateAddress(address string) (bool, error)

Validate the given address.

Parameters

Type Name Required Description
string address Yes Address

Return Value

(bool, error)

crypto.private_key

PrivateKeyFromPassphrase()

1func PrivateKeyFromPassphrase(passphrase string) (*PrivateKey, error)

Derive the private key for the given passphrase.

Parameters

Type Name Required Description
string passphrase Yes Passphrase

Return Value

*PrivateKey, error

PrivateKeyFromHex()

1func PrivateKeyFromHex(privateKeyHex string) (*PrivateKey, error)

Create a private key instance from a hex string.

Parameters

Type Name Required Description
string privateKeyHex Yes Private key

Return Value

*PrivateKey, error

PrivateKeyFromBytes()

1func PrivateKeyFromBytes(bytes []byte) *PrivateKey

Create a private key instance from a bytes string.

Parameters

Type Name Required Description
[]byte bytes Yes Bytes string

Return Value

*PrivateKey

ToHex()

1func (privateKey *PrivateKey) ToHex() string

Convert a private key instance to a hex string.

Parameters

Type Name Required Description
*PrivateKey bytes Yes Private key

Return Value

string

ToAddress()

1func (privateKey *PrivateKey) ToAddress() string

Create a private key instance to a address.

Parameters

Type Name Required Description
*PrivateKey bytes Yes Private key

Return Value

string

ToWif()

1func (privateKey *PrivateKey) ToWif() string

Create a private key instance to a WIF string.

Parameters

Type Name Required Description
*PrivateKey bytes Yes Private key

Return Value

string

Sign()

1func (privateKey *PrivateKey) Sign(hash []byte) ([]byte, error)

Sign the private key.

Parameters

Type Name Required Description
[]byte hash Yes Private key

Return Value

[]byte, error

Verify()

1func (publicKey *PublicKey) Verify(signature []byte, data []byte) (bool, error)

Verify the private key.

Parameters

Type Name Required Description
[]byte signature Yes Signature
[]byte data Yes Private key

Return Value

bool, error

crypto.public_key

PublicKeyFromPassphrase()

1func PublicKeyFromPassphrase(passphrase string) (*PublicKey, error)

Derive the public from the given passphrase.

Parameters

Type Name Required Description
string passphrase Yes Passphrase

Return Value

*PublicKey, error

PublicKeyFromHex()

1func PublicKeyFromHex(publicKeyHex string) (*PublicKey, error)

Create a public key instance from a hex string.

Parameters

Type Name Required Description
string publicKeyHex Yes Hex string

Return Value

*PublicKey, error

PublicKeyFromBytes()

1func PublicKeyFromBytes(bytes []byte) (*PublicKey, error)

Create a public key instance from a bytes string.

Parameters

Type Name Required Description
[]byte bytes Yes Bytes string

Return Value

*PublicKey, error

ToHex()

1func (publicKey *PublicKey) ToHex() string

Convert a public key instance to a hex string.

Parameters

Type Name Required Description
*PublicKey publicKey Yes Public key

Return Value

string

ToAddress()

1func (publicKey *PublicKey) ToAddress() string

Convert a public key instance to a valid address.

Parameters

Type Name Required Description
*PublicKey publicKey Yes Public key

Return Value

string

crypto.builder

buildSignedTransaction()

1func buildSignedTransaction(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a signed transaction.

Parameters

Type Name Required Description
*Transaction transaction Yes Transaction
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

BuildTransfer()

1func BuildTransfer(recipient string, amount FlexToshi, vendorField string, passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a transfer.

Parameters

Type Name Required Description
string recipient Yes Recipient identifier
FlexToshi amount Yes Transaction amount
string vendorField Yes Transaction vendorfield
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

BuildSecondSignatureRegistration()

1func BuildSecondSignatureRegistration(passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a second signature registration.

Parameters

Type Name Required Description
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

BuildDelegateRegistration()

1func BuildDelegateRegistration(username string, passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a delegate registration.

Parameters

Type Name Required Description
string username Yes Delegate username
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

BuildVote()

1func BuildVote(vote, passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a vote registration.

Parameters

Type Name Required Description
? vote Yes Vote
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

BuildMultiSignatureRegistration()

1func BuildMultiSignatureRegistration(min byte, lifetime byte, keysgroup []string, passphrase string, secondPassphrase string) *Transaction

Builds a transaction for a multi signature registration.

Parameters

Type Name Required Description
byte min Yes Transaction minimum required signatures
byte lifetime Yes Transaction lifetime
[]string keysgroup Yes Transaction keysgroup
string passphrase Yes Passphrase
string secondPassphrase Yes Second passphrase

Return Value

*Transaction

crypto.serializer

SerializeTransaction()

1func SerializeTransaction(transaction *Transaction) []byte

Handle the serialization of “transaction” data.

Parameters

Type Name Required Description
*Transaction transaction Yes Transaction

Return Value

[]byte

serializeHeader()

1func serializeHeader(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “headers” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeVendorField()

1func serializeVendorField(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of the vendorfield.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeTypeSpecific()

1func serializeTypeSpecific(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the deserialization of “type” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeSignatures()

1func serializeSignatures(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the deserialization of “signature” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

crypto.deserializer

DeserializeTransaction()

1func DeserializeTransaction(serialized string) *Transaction

Handle the deserialization of “transaction” data

Parameters

Type Name Required Description
string serialized Yes Serialized

Return Value

*Transaction

deserializeHeader()

1func deserializeHeader(bytes []byte, transaction *Transaction) (int, *Transaction)

Handle the deserialization of “headers” data

Parameters

Type Name Required Description
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeTypeSpecific()

1func deserializeTypeSpecific(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization for a given type of transaction.

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeVersionOne()

1func deserializeVersionOne(bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization for a version one transaction.

Parameters

Type Name Required Description
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeTransfer()

1func deserializeTransfer(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “transfer” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeSecondSignatureRegistration()

1func deserializeSecondSignatureRegistration(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “second signature registration” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeDelegateRegistration()

1func deserializeDelegateRegistration(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “delegate registration” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeVote()

1func deserializeVote(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “vote” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeMultiSignatureRegistration()

1func deserializeMultiSignatureRegistration(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “multi signature registration” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeIpfs()

1func deserializeIpfs(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “ipfs” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeTimelockTransfer()

1func deserializeTimelockTransfer(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “timelock transfer” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeMultiPayment()

1func deserializeMultiPayment(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “multi payments” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

deserializeDelegateResignation()

1func deserializeDelegateResignation(assetOffset int, bytes []byte, transaction *Transaction) *Transaction

Handle the deserialization of “delegate resignation” data

Parameters

Type Name Required Description
int assetOffset Yes Offset
[]byte bytes Yes
*Transaction transaction Yes Transaction

Return Value

*Transaction

serializeTransfer()

1func serializeTransfer(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “transfer” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeSecondSignatureRegistration()

1func serializeSecondSignatureRegistration(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “second signature registration” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeDelegateRegistration()

1func serializeDelegateRegistration(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “delegate registration” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeVote()

1func serializeVote(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “vote” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeMultiSignatureRegistration()

1func serializeMultiSignatureRegistration(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “multi signature registration” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeIpfs()

1func serializeIpfs(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “ipfs” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeTimelockTransfer()

1func serializeTimelockTransfer(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “timelock transfer” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeMultiPayment()

1func serializeMultiPayment(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “multi payment” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

serializeDelegateResignation()

1func serializeDelegateResignation(buffer *bytes.Buffer, transaction *Transaction) *bytes.Buffer

Handle the serialization of “delegate resignation” data.

Parameters

Type Name Required Description
*bytes.Buffer buffer Yes Buffer
*Transaction transaction Yes Transaction

Return Value

*bytes.Buffer

crypto.transaction

GetId()

1func (transaction *Transaction) GetId() string

Convert the byte representation to a unique identifier.

Return Value

string

Sign()

1func (transaction *Transaction) Sign(passphrase string)

Sign the transaction using the given passphrase.

Parameters

Type Name Required Description
string passphrase Yes Passphrase

SecondSign()

1func (transaction *Transaction) SecondSign(passphrase string)

Sign the transaction using the given second passphrase.

Parameters

Type Name Required Description
string passphrase Yes Second passphrase

Verify()

1func (transaction *Transaction) Verify() (bool, error)

Verify the transaction.

Return Value

bool, error

SecondVerify()

1func (transaction *Transaction) SecondVerify(secondPublicKey *PublicKey) (bool, error)

Verify the transaction with a second public key.

Parameters

Type Name Required Description
*PublicKey secondPublicKey Yes Second public key

Return Value

(bool, error)

ParseSignatures()

1func (transaction *Transaction) ParseSignatures(startOffset int) *Transaction

Parse the signature, second signature and multi signatures.

Parameters

Type Name Required Description
int startOffset Yes Offset

Return Value

*Transaction

ToMap()

1func (transaction *Transaction) ToMap() map[string]interface{}

Convert the transaction to its map representation.

Return Value

map[string]interface{}

ToJson()

1func (transaction *Transaction) ToJson() (string, error)

Convert the transaction to its JSON representation.

Return Value

string, error

ToBytes()

1func (transaction *Transaction) ToBytes(skipSignature, skipSecondSignature bool) []byte

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

[]byte

Serialize()

1func (transaction *Transaction) Serialize() []byte

Perform AIP11 compliant serialization

Return Value

[]byte

crypto.message

SignMessage()

1func SignMessage(message string, passphrase string) (*Message, error)

Sign a message using the given passphrase.

Parameters

Type Name Required Description
string message Yes Message
string passphrase Yes Passphrase

Return Value

*Message, error

Verify()

1func (message *Message) Verify() (bool, error)

Verify the message content.

Parameters

Type Name Required Description
*Message message Yes Message

Return Value

bool, error

ToMap()

1func (message *Message) ToMap() map[string]interface{}

Convert the message to its map representation

Parameters

Type Name Required Description
*Message message Yes Message

Return Value

map[string]interface{}

ToJson()

1func (message *Message) ToJson() (string, error)

Convert the message to its JSON representation

Parameters

Type Name Required Description
*Message message Yes Message

Return Value

string

crypto.slot

GetTime()

1func GetTime() int32

Get the time diff between now and network start.

Return Value

int32

GetEpoch()

1func GetEpoch() uint32

Get the network start epoch.

Return Value

uint32

Last updated 3 years ago
Edit Page
Share: