API Documentation

crypto.configuration

SetNetwork()

func 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()

func GetNetwork() *Network

Get settings for a selected network, default network is devnet

Return Value

*Network

GetFee()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func (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()

func (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()

func (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()

func (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()

func (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()

func 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()

func 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()

func 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()

func (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()

func (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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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

SerialiseTransaction()

func SerialiseTransaction(transaction *Transaction) []byte

Handle the serialization of "transaction" data.

Parameters

Type

Name

Required

Description

*Transaction

transaction

Yes

Transaction

Return Value

[]byte

serializeHeader()

func 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()

func 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()

func 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()

func 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()

func DeserializeTransaction(serialized string) *Transaction

Handle the deserialization of "transaction" data

Parameters

Type

Name

Required

Description

string

serialized

Yes

Serialized

Return Value

*Transaction

deserializeHeader()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func 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()

func (transaction *Transaction) GetId() string

Convert the byte representation to a unique identifier.

Return Value

string

Sign()

func (transaction *Transaction) Sign(passphrase string)

Sign the transaction using the given passphrase.

Parameters

Type

Name

Required

Description

string

passphrase

Yes

Passphrase

SecondSign()

func (transaction *Transaction) SecondSign(passphrase string)

Sign the transaction using the given second passphrase.

Parameters

Type

Name

Required

Description

string

passphrase

Yes

Second passphrase

Verify()

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

Verify the transaction.

Return Value

bool, error

SecondVerify()

func (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()

func (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()

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

Convert the transaction to its map representation.

Return Value

map[string]interface{}

ToJson()

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

Convert the transaction to its JSON representation.

Return Value

string, error

ToBytes()

func (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()

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

Perform AIP11 compliant serialization

Return Value

[]byte

crypto.message

SignMessage()

func 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()

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

Verify the message content.

Parameters

Type

Name

Required

Description

*Message

message

Yes

Message

Return Value

bool, error

ToMap()

func (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()

func (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()

func GetTime() int32

Get the time diff between now and network start.

Return Value

int32

GetEpoch()

func GetEpoch() uint32

Get the network start epoch.

Return Value

uint32