archethic

package module
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: AGPL-3.0 Imports: 40 Imported by: 5

README

Archethic's golang library

Official Archethic golang library

Installing

go get github.com/archethic-foundation/libgo

Usage

This library aims to provide an easy way to create Archethic transaction and to send them over the network.

API

Cryptographic functions
deriveKeyPair(seed, index, curve)

It creates a new keypair into hexadecimal format

  • seed is a slice of bytes representing the transaction chain seed to be able to derive and generate the keys
  • index is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)
  • curve is the elliptic curve to use for the key generation (can be "ED25519", "P256", "SECP256K1")
import (
    ...
	archethic "github.com/archethic-foundation/libgo"
)

    publicKey, privateKey := archethic.DeriveKeypair([]byte("seed"), uint32(0), archethic.ED25519)
    publicKeyHex := hex.EncodeToString(publicKey)
    // publicKeyHex: 000161d6cd8da68207bd01198909c139c130a3df3a8bd20f4bacb123c46354ccd52c

deriveAddress(seed, index, curve, hashAlgo)

It creates a transaction address by extract the public key from the key derivation and hash it into a hexadecimal format

  • seed is a slice of bytes representing the transaction chain seed to be able to derive and generate the keys
  • index is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)
  • curve is the elliptic curve to use for the key generation (can be "ED25519", "P256", "SECP256K1")
  • hashAlgo is the hash algorithm to create the address (can be "SHA256", "SHA512", "SHA3_256", "SHA3_512", "BLAKE2B")
import(
 ...
 archethic "github.com/archethic-foundation/libgo"
 )
address := archethic.DeriveAddress([]byte("mysuperseed"), uint32(0), archethic.ED25519, archethic.SHA256)
// Address: 0000b0c17f85ca19e3db670992e79adb94fb560bd750fda06d45bc0a42912c89d31e
ecEncrypt(data, publicKey)

Perform an ECIES encryption using a public key and a data

  • data Data to encrypt
  • publicKey Public key to derive a shared secret and for whom the content must be encrypted
import (
  ...
  archethic "github.com/archethic-foundation/libgo"
  )

	textToEncrypt := []byte("hello")
  publicKey, _ := archethic.DeriveKeypair([]byte("seed"), 0, archethic.P256)
  cipherText := archethic.EcEncrypt(textToEncrypt, publicKey)
aesEncrypt(data, publicKey)

Perform an AES encryption using a key and a data

  • data Data to encrypt
  • key Symmetric key
  import (
  ...
  archethic "github.com/archethic-foundation/libgo"
  )

  key := make([]byte, 32)
  rand.Read(key)
  dataToEncrypt := []byte("hello")
  encryptedData := archethic.AesEncrypt(dataToEncrypt, key)

Transaction building

tx := archethic.TransactionBuilder{} creates a new instance of the transaction

The transaction instance contains the following methods:

SetType(type)

Sets the type of the transaction (could be TransferType, ContractType, DataType, TokenType, HostingType, CodeProposalType, CodeApprovalType)

SetCode(code)

Adds the code in the data.code section of the transaction code is a string defining the smart contract

SetContent(content)

Adds the content in the data.content section of the transaction content is a string defining the smart contract

AddOwnership(secret, authorizedKeys)

Adds an ownership in the data.ownerships section of the transaction with a secret and its related authorized public keys to be able to decrypt it. This aims to prove the ownership or the delegatation of some secret to a given list of public keys. secret is the slice of bytes representing the encrypted secret authorizedKeys is a list of object represented by

  • publicKey is the slice of bytes representing the public key
  • encryptedSecretKey is the slice of bytes representing the secret key encrypted with the public key (see ecEncrypt)
AddUCOTransfer(to, amount)

Adds a UCO transfer to the data.ledger.uco.transfers section of the transaction

  • to is the slice of bytes representing the transaction address (recipient) to receive the funds
  • amount is the number of uco to send, the ToUint64(number float64, decimals int) uint64 function can help build the proper amount, for example ToUint64(10.03, 8)
AddTokenTransfer(to, tokenAddress, amount, tokenId)

Adds a token transfer to the data.ledger.token.transfers section of the transaction

  • to is the slice of bytes representing the transaction address (recipient) to receive the funds
  • tokenAddress is the slice of bytes representing the token address to spend
  • amount is the number of uco to send, the ToUint64(number float64, decimals int) uint64 function can help build the proper amount, for example ToUint64(10.03, 8)
  • tokenId is the ID of the token to use
AddRecipient(to)

Adds a recipient to call the smart contract's "transaction" action.

  • to is the contract's address in hexadecimal
AddRecipientWithNamedAction(to, action, args)

Adds a recipient to call a specific smart contract's action.

  • to is the contract's address in hexadecimal
  • action is the name of the action
  • args is the list of arguments of the action
Build(seed, index, curve, hashAlgo)

Generates address, timestamp, previousPublicKey, previousSignature of the transaction and serialize it using a custom binary protocol.

  • seed is the slice of bytes representing the transaction chain seed to be able to derive and generate the keys
  • index is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)
  • curve is the elliptic curve to use for the key generation (can be "ED25519", "P256", "SECP256K1")
  • hashAlgo is the hash algorithm to use to generate the address (can be "SHA256", "SHA512", "SHA3_256", "SHA3_512", "BLAKE2B")

import(
  ...
  archethic "github.com/archethic-foundation/libgo"
  )
  tx := archethic.TransactionBuilder{}
  tx.SetType(archethic.TransferType)
  ucoAddress, _ := hex.DecodeString("0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646")

  tx.AddUcoTransfer(
  	ucoAddress,
  	archethic.ToUint64(0.420, 8),
  )
  tx.Build([]byte("mysuperpassphraseorseed"), 0, archethic.ED25519, archethic.SHA256)

OriginSign(privateKey)

Sign the transaction with an origin device private key

  • privateKey is the slice of bytes representing the private key to generate the origin signature to able to perform the ProofOfWork and authorize the transaction
  import(
  ...
  archethic "github.com/archethic-foundation/libgo"
  )

  originPublicKey, originPrivateKey := archethic.DeriveKeypair([]byte("origin_seed"), 0, archethic.P256)

  tx := archethic.TransactionBuilder{}
  tx.SetType(archethic.TransferType)

  tx.Build([]byte("seed"), 0, archethic.P256, archethic.SHA256)
  tx.OriginSign(originPrivateKey)
  log.Println(tx.Version)

  // test, err := archethic.Verify(tx.OriginSignature, tx.OriginSignaturePayload(), originPublicKey)
ToJSON()

Export the transaction generated into JSON

import(
 ...
 archethic "github.com/archethic-foundation/libgo"
 )

 tx := archethic.TransactionBuilder{}
 tx.SetType(archethic.TransferType)
 ucoAddress, _ := hex.DecodeString("0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646")

 tx.AddUcoTransfer(
 	ucoAddress,
 	archethic.ToUint64(0.420, 8),
 )
 tx.Build([]byte("mysuperpassphraseorseed"), 0, archethic.ED25519, archethic.SHA256)
 json, _ := tx.ToJSON()

Remote Endpoint calls
GetOriginKey()

Return the hardcoded origin private key for software, this is used for signing transaction (see OriginSign).

AddOriginKey(originPublicKey, certificate, endpoint)

Query a node to add a new origin public to be authorized to sign transaction with the corresponding private key (see OriginSign).

  • originPublicKey is the public key to be added.
  • certificate is the certificate that prove the public key is allowed to be added.
  client := archethic.NewAPIClient("http://localhost:4000")

  client.AddOriginKey("01103109", "mycertificate")
GetLastTransactionIndex(address)

Query a node to find the length of the chain to retrieve the transaction index

  • addresses Transaction address (in hexadecimal)
  client := archethic.NewAPIClient("http://localhost:4000")
  client.GetLastTransactionIndex("0000872D96130A2963F1195D1F85FC316AE966644F2E3EE45469C2A257F49C4631C2")
GetStorageNoncePublicKey()

Query a node to find the public key of the shared storage node key

 client := archethic.NewAPIClient("https://testnet.archethic.net/api")
 client.GetStorageNoncePublicKey()
 // 00017877BCF4122095926A49489009649603AB129822A19EF9D573B8FD714911ED7F
GetTransactionFee(tx)

Query a node to fetch the tx fee for a given transaction

  • tx Generated transaction

  client := archethic.NewAPIClient("http://localhost:4000")

  tx := archethic.TransactionBuilder{}
  tx.SetType(archethic.TransferType)
  ucoAddress, _ := hex.DecodeString("0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646")

  tx.AddUcoTransfer(
  	ucoAddress,
  	archethic.ToUint64(0.420, 8),
  )
  tx.Build([]byte("mysuperpassphraseorseed"), 0, archethic.ED25519, archethic.SHA256)
  client.GetTransactionFee(&tx)
GetTransactionOwnerships(addresses)

Query a node to find the ownerships (secrets and authorized keys) to given transactions addresses

  • addresses: Transaction address
  client := archethic.NewAPIClient("http://localhost:4000")
  client.GetTransactionOwnerships("0000872D96130A2963F1195D1F85FC316AE966644F2E3EE45469C2A257F49C4631C2")


Keychain / Wallet management
NewKeychainTransaction(seed []byte, authorizedPublicKeys [][]byte) TransactionBuilder

Creates a new transaction to build a keychain by embedding the on-chain encrypted wallet.

  • seed Keychain's seed
  • authorizedPublicKeys List of authorized public keys able to decrypt the wallet
NewAccessTransaction(seed []byte, keychainAddress []byte) TransactionBuilder

Creates a new keychain access transaction to allow a seed and its key to access a keychain

  • seed Keychain access's seed
  • keychainAddress Keychain's tx address
GetKeychain(seed []byte, client APIClient) *Keychain

Retrieve a keychain from the keychain access transaction and decrypt the wallet to retrieve the services associated

  • seed Keychain access's seed
  • client the API client
client := archethic.NewAPIClient("http://localhost:4000")
keychain := archethic.GetKeychain([]byte("seed"), *client)

Once retrieved the keychain provide the following methods:

(k Keychain) BuildTransaction(transaction TransactionBuilder, serviceName string, index uint8) TransactionBuilder

Generate address, previousPublicKey, previousSignature of the transaction and serialize it using a custom binary protocol, based on the derivation path, curve and hash algo of the service given in param.

  • transaction is an instance of TransactionBuilder
  • serviceName is the service name to use for getting the derivation path, the curve and the hash algo
  • index is the number of transactions in the chain, to generate the actual and the next public key (see the cryptography section)

Returns is the signed TransactionBuilder.


seed := []byte("seed")

keychain := archethic.Keychain{Seed: seed, Version: 1, Services: map[string]Service{
  "uco": {
    DerivationPath: "m/650'/0/0",
    Curve:          ED25519,
    HashAlgo:       SHA256,
  },
}}

tx := archethic.TransactionBuilder{TxType: TransferType}
ucoAddress, _ := hex.DecodeString("0000b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646")
tx.AddUcoTransfer(
  ucoAddress,
  archethic.ToUint64(10.0, 8),
)

tx = keychain.BuildTransaction(tx, "uco", 0)

(k Keychain) DeriveAddress(serviceName string, index uint8) []byte

Derive an address for the given service at the index given

  • service: Service name to identify the derivation path to use
  • index: Chain index to derive
seed := []byte("abcdefghijklmnopqrstuvwxyz")
  keychain := archethic.NewKeychain(seed)
  publicKey, _ := keychain.DeriveKeypair("uco", 0)
  address := archethic.DeriveAddress(seed, 0, keychain.Services["uco"].Curve, keychain.Services["uco"].HashAlgo)
(k Keychain) DeriveKeypair(serviceName string, index uint8) ([]byte, []byte)

Derive a keypair for the given service at the index given

  • service: Service name to identify the derivation path to use
  • index: Chain index to derive
seed := []byte("abcdefghijklmnopqrstuvwxyz")
  keychain := archethic.NewKeychain(seed)
  publicKey, _ := keychain.DeriveKeypair("uco", 0)
(k Keychain) ToDID() DID

Return a Decentralized Identity document from the keychain. (This is used in the transaction's content of the keychain tx)

seed := []byte("abcdefghijklmnopqrstuvwxyz")
  keychain := archethic.NewKeychain(seed)
  did := keychain.ToDID()
log.Println(string(did.ToJSON()))

{
  "@context": [
     "https://www.w3.org/ns/did/v1"
  ],
  "id": "did:archethic:keychain_address",
  "authentification": servicesMaterials, //list of public keys of the services
  "verificationMethod": servicesMaterials //list of public keys of the services
}
(k *Keychain) AddService(name string, derivationPath string, curve Curve, hashAlgo HashAlgo)

Add a service into the keychain

  • name: Name of the service to add
  • derivationPath: Crypto derivation path
  • curve: Elliptic curve to use
  • hashAlgo: Hash algo
	keychain := archethic.NewKeychain([]byte("seed"))
  keychain.AddService("nft1", "m/650'/1/0", archethic.ED25519, archethic.SHA256)
  log.Println(keychain.Services)
//map[nft1:{m/650'/1/0 0 0} uco:{m/650'/0/0 1 0}]

Running the tests

go test

Documentation

Index

Constants

View Source
const (
	Version            uint32          = 3
	KeychainType       TransactionType = 255
	KeychainAccessType TransactionType = 254
	TransferType       TransactionType = 253
	HostingType        TransactionType = 252
	TokenType          TransactionType = 251
	DataType           TransactionType = 250
	ContractType       TransactionType = 249
	CodeProposalType   TransactionType = 5
	CodeApprovalType   TransactionType = 6
)

Variables

This section is empty.

Functions

func Add

func Add(a, b int) int

func AesDecrypt

func AesDecrypt(cipherText, key []byte) ([]byte, error)

func AesEncrypt

func AesEncrypt(data, key []byte) ([]byte, error)

func DecodeVarInt added in v1.0.8

func DecodeVarInt(bytes []byte) (uint64, []byte)

DecodeVarInt convert a VarInt binary into a integer

func DeriveAddress

func DeriveAddress(seed []byte, index uint32, curve Curve, hashAlgo HashAlgo) ([]byte, error)

func DeriveArchethicKeypair

func DeriveArchethicKeypair(seed []byte, derivationPath string, index uint8, curve Curve) ([]byte, []byte, error)

func DeriveKeypair

func DeriveKeypair(seed []byte, index uint32, curve Curve) ([]byte, []byte, error)

DeriveKeypair generate a keypair using a derivation function with a seed and an index. Each keys is prepending with a curve identification.

func DeserializeTypedData added in v1.0.8

func DeserializeTypedData(bin []byte) (any, []byte, error)

func EcDecrypt

func EcDecrypt(cipherText []byte, privateKey []byte) ([]byte, error)

func EcEncrypt

func EcEncrypt(data []byte, publicKey []byte) ([]byte, error)

func EncodeInt32

func EncodeInt32(number uint32) []byte

func EncodeInt64

func EncodeInt64(number uint64) []byte

func EncodeVarInt added in v1.0.8

func EncodeVarInt(number uint64) []byte

EncodeVarInt converts a number into a VarInt binary

func FromBigInt added in v1.0.8

func FromBigInt(number uint64) float64

func GenerateDeterministicKeypair

func GenerateDeterministicKeypair(pvKey []byte, curve Curve, originID OriginID) ([]byte, []byte, error)

GenerateDeterministicKeypair generate a new keypair deterministically with a given private key, curve and origin id

func Hash

func Hash(content []byte, hashAlgo HashAlgo) ([]byte, error)

Hash create a hash digest from the data with an hash algorithm identification prepending the digest

func KeyToJWK

func KeyToJWK(publicKey []byte, keyId string) (map[string]string, error)

func MaybeConvertToHex

func MaybeConvertToHex(inputString string) ([]byte, error)

MaybeConvertToHex converts a string to a byte array if it is a hex string, otherwise it returns the string as a byte array

func OriginPrivateKey added in v1.0.9

func OriginPrivateKey() []byte

func SerializeTypedData added in v1.0.8

func SerializeTypedData(val interface{}) ([]byte, error)

func Sign

func Sign(privateKey []byte, data []byte) ([]byte, error)

func ToBigInt added in v1.0.8

func ToBigInt(number float64) uint64

func ToUint64

func ToUint64(number float64, decimals int) (uint64, error)

func Verify

func Verify(sig []byte, data []byte, publicKey []byte) (bool, error)

Types

type APIClient

type APIClient struct {
	// contains filtered or unexported fields
}

func NewAPIClient

func NewAPIClient(baseURL string) *APIClient

func (*APIClient) AddOriginKey

func (c *APIClient) AddOriginKey(originPublicKey, certificate string) (SendTransactionResponse, error)

func (*APIClient) GetBalance

func (c *APIClient) GetBalance(address string) (Balance, error)

func (*APIClient) GetLastTransactionIndex

func (c *APIClient) GetLastTransactionIndex(address string) int

func (*APIClient) GetLastTransactionOwnerships

func (c *APIClient) GetLastTransactionOwnerships(address string) ([]Ownership, error)

func (*APIClient) GetNearestEndpoints

func (c *APIClient) GetNearestEndpoints() (*NearestEndpointsGQL, error)

func (*APIClient) GetOracleData

func (c *APIClient) GetOracleData(timestamp ...int64) (OracleData, error)

func (*APIClient) GetStorageNoncePublicKey

func (c *APIClient) GetStorageNoncePublicKey() (string, error)

func (*APIClient) GetToken

func (c *APIClient) GetToken(address string) (Token, error)

func (*APIClient) GetTransactionFee

func (c *APIClient) GetTransactionFee(tx *TransactionBuilder) (Fee, error)

func (*APIClient) GetTransactionOwnerships

func (c *APIClient) GetTransactionOwnerships(address string) ([]Ownership, error)

func (*APIClient) InjectHTTPClient

func (c *APIClient) InjectHTTPClient(httpClient *http.Client)

func (*APIClient) SendTransaction added in v1.0.4

func (c *APIClient) SendTransaction(tx *TransactionBuilder) (SendTransactionResponse, error)

func (*APIClient) SimulateContractExecution added in v1.0.4

func (c *APIClient) SimulateContractExecution(tx *TransactionBuilder) ([]SimulateResponse, error)

func (*APIClient) SubscribeToOracleUpdates

func (c *APIClient) SubscribeToOracleUpdates(handler func(OracleData))

type AbsintheSubscription

type AbsintheSubscription struct {
	// contains filtered or unexported fields
}

func (*AbsintheSubscription) CancelSubscription

func (a *AbsintheSubscription) CancelSubscription()

func (*AbsintheSubscription) GraphqlSubscription

func (a *AbsintheSubscription) GraphqlSubscription(wsUrl, query string, variables map[string]string, readyHandler func(), handler func(map[string]interface{}) error)

type Address

type Address string

type AuthorizedKey

type AuthorizedKey struct {
	PublicKey          []byte
	EncryptedSecretKey []byte
}

type Balance

type Balance struct {
	Uco   int
	Token []struct {
		Address []byte
		Amount  int
		TokenId int
	}
}

type BalanceGQL

type BalanceGQL struct {
	Uco   int
	Token []struct {
		Address Address
		Amount  int
		TokenId int
	}
}

type Curve

type Curve uint8
const (
	ED25519   Curve = 0
	P256      Curve = 1
	SECP256K1 Curve = 2
)

type DID

type DID struct {
	Context            []string         `json:"@context"`
	Id                 string           `json:"id"`
	Authentication     []string         `json:"authentication"`
	VerificationMethod []DIDKeyMaterial `json:"verificationMethod"`
}

func (DID) ToJSON

func (d DID) ToJSON() []byte

type DIDKeyMaterial

type DIDKeyMaterial struct {
	Id           string            `json:"id"`
	KeyType      string            `json:"type"`
	PublicKeyJwk map[string]string `json:"publicKeyJwk"`
	Controller   string            `json:"controller"`
}

type EncodedType added in v1.0.8

type EncodedType uint8
const (
	IntegerType EncodedType = 0
	FloatType   EncodedType = 1
	StringType  EncodedType = 2
	ListType    EncodedType = 3
	MapType     EncodedType = 4
	BoolType    EncodedType = 5
	NilType     EncodedType = 6
)

type ErrorContext

type ErrorContext string

type Fee

type Fee struct {
	Fee   float32
	Rates struct {
		Eur float32
		Usd float32
	}
}

type HashAlgo

type HashAlgo uint8
const (
	SHA256   HashAlgo = 0
	SHA512   HashAlgo = 1
	SHA3_256 HashAlgo = 2
	SHA3_512 HashAlgo = 3
	BLAKE2B  HashAlgo = 4
)

type Hex

type Hex string

type Keychain

type Keychain struct {
	Seed                 []byte
	Version              uint8
	Services             map[string]Service
	AuthorizedPublicKeys [][]byte
}

func DecodeKeychain

func DecodeKeychain(binaryInput []byte) *Keychain

func GetKeychain

func GetKeychain(seed []byte, client APIClient) (*Keychain, error)

func NewKeychain

func NewKeychain(seed []byte) *Keychain

NewKeychain instanciates a new Keychain struct

func (*Keychain) AddAuthorizedPublicKey

func (k *Keychain) AddAuthorizedPublicKey(publicKey []byte)

func (*Keychain) AddService

func (k *Keychain) AddService(name string, derivationPath string, curve Curve, hashAlgo HashAlgo)

func (Keychain) BuildTransaction

func (k Keychain) BuildTransaction(transaction *TransactionBuilder, serviceName string, index uint8) error

func (Keychain) DeriveAddress

func (k Keychain) DeriveAddress(serviceName string, index uint8) ([]byte, error)

func (Keychain) DeriveKeypair

func (k Keychain) DeriveKeypair(serviceName string, index uint8) ([]byte, []byte, error)

func (*Keychain) RemoveAuthorizedPublicKey

func (k *Keychain) RemoveAuthorizedPublicKey(publicKey []byte)

func (*Keychain) RemoveService

func (k *Keychain) RemoveService(name string)

func (Keychain) ToDID

func (k Keychain) ToDID() (*DID, error)

type LastTransactionOwnershipsGQL

type LastTransactionOwnershipsGQL struct {
	LastTransaction struct {
		Data struct {
			Ownerships []OwnershipGQL
		}
	} `graphql:"lastTransaction(address: $address)"`
}

type Ledger

type Ledger struct {
	Uco   UcoLedger
	Token TokenLedger
}

type NearestEndpointsGQL

type NearestEndpointsGQL struct {
	NearestEndpoints []struct {
		IP   string
		Port int
	}
}

type OracleData

type OracleData struct {
	Timestamp Timestamp
	Services  struct {
		Uco struct {
			Eur float32
			Usd float32
		}
	}
}

type OriginID

type OriginID uint8
const (
	KEYCHAIN_ORIGIN_ID OriginID = 0
	SOFTWARE_ORIGIN_ID OriginID = 1
)

type Ownership

type Ownership struct {
	Secret         []byte
	AuthorizedKeys []AuthorizedKey
}

type OwnershipGQL

type OwnershipGQL struct {
	Secret               Hex
	AuthorizedPublicKeys []struct {
		EncryptedSecretKey Hex
		PublicKey          PublicKey
	}
}

type PublicKey

type PublicKey string

type Recipient added in v1.0.5

type Recipient struct {
	Address []byte
	Action  []byte
	Args    []interface{}
}

type SendTransactionResponse added in v1.0.4

type SendTransactionResponse struct {
	TransactionAddress string `json:"transaction_address"`
	Status             string
}

type Service

type Service struct {
	DerivationPath string   `json:"derivationPath"`
	Curve          Curve    `json:"curve"`
	HashAlgo       HashAlgo `json:"hashAlgo"`
}

type SimulateResponse added in v1.0.4

type SimulateResponse struct {
	RecipientAddress string `json:"recipient_address"`
	Valid            bool
	Error            SimulateResponseError
}

type SimulateResponseError added in v1.0.4

type SimulateResponseError struct {
	Code    int
	Message string
	Data    map[string]interface{}
}

type Timeout

type Timeout struct {
	// contains filtered or unexported fields
}

func SetTimeout

func SetTimeout(callback func(), duration time.Duration) *Timeout

func (*Timeout) Clear

func (t *Timeout) Clear()

type Timestamp

type Timestamp int64

func (Timestamp) GetGraphQLType

func (t Timestamp) GetGraphQLType() string

type Token

type Token struct {
	Genesis    []byte
	Name       string
	Symbol     string
	Supply     int
	Type       string
	Properties [2]interface{}
	Collection [][2]interface{}
	Id         string
	Decimals   int
}

type TokenGQL

type TokenGQL struct {
	Genesis    Address
	Name       string
	Symbol     string
	Supply     int
	Type       string
	Properties [2]interface{}
	Collection [][2]interface{}
	Id         string
	Decimals   int
}

type TokenLedger

type TokenLedger struct {
	Transfers []TokenTransfer
}

type TokenProperties

type TokenProperties map[string]interface{}

type TokenTransfer

type TokenTransfer struct {
	To           []byte
	TokenAddress []byte
	TokenId      int
	Amount       uint64
}

type TransactionBuilder

type TransactionBuilder struct {
	Version           uint32
	Address           []byte
	TxType            TransactionType
	Data              TransactionData
	PreviousPublicKey []byte
	PreviousSignature []byte
	OriginSignature   []byte
}

func NewAccessTransaction

func NewAccessTransaction(seed []byte, keychainAddress []byte) (*TransactionBuilder, error)

func NewKeychainTransaction

func NewKeychainTransaction(keychain *Keychain, transactionChainIndex uint32) (*TransactionBuilder, error)

func NewTransaction

func NewTransaction(txType TransactionType) *TransactionBuilder

New transaction builder instance

func (*TransactionBuilder) AddOwnership

func (t *TransactionBuilder) AddOwnership(secret []byte, authorizedKeys []AuthorizedKey)

func (*TransactionBuilder) AddRecipient

func (t *TransactionBuilder) AddRecipient(address []byte)

func (*TransactionBuilder) AddRecipientWithNamedAction added in v1.0.5

func (t *TransactionBuilder) AddRecipientWithNamedAction(address []byte, action []byte, args []interface{})

func (*TransactionBuilder) AddTokenTransfer

func (t *TransactionBuilder) AddTokenTransfer(to []byte, tokenAddress []byte, amount uint64, tokenId int)

func (*TransactionBuilder) AddUcoTransfer

func (t *TransactionBuilder) AddUcoTransfer(to []byte, amount uint64)

func (*TransactionBuilder) Build

func (t *TransactionBuilder) Build(seed []byte, index uint32, curve Curve, hashAlgo HashAlgo) error

func (*TransactionBuilder) OriginSign

func (t *TransactionBuilder) OriginSign(originPrivateKey []byte) error

func (TransactionBuilder) OriginSignaturePayload

func (t TransactionBuilder) OriginSignaturePayload() []byte

func (*TransactionBuilder) SetAddress

func (t *TransactionBuilder) SetAddress(address []byte)

func (*TransactionBuilder) SetCode

func (t *TransactionBuilder) SetCode(code string)

func (*TransactionBuilder) SetContent

func (t *TransactionBuilder) SetContent(content []byte)

func (*TransactionBuilder) SetPreviousSignatureAndPreviousPublicKey

func (tx *TransactionBuilder) SetPreviousSignatureAndPreviousPublicKey(prevSign []byte, prevPubKey []byte)

func (*TransactionBuilder) SetType

func (t *TransactionBuilder) SetType(txType TransactionType)

func (*TransactionBuilder) ToJSONMap added in v1.0.4

func (t *TransactionBuilder) ToJSONMap() (map[string]interface{}, error)

type TransactionConfirmedGQL

type TransactionConfirmedGQL struct {
	NbConfirmations  int
	MaxConfirmations int
}

type TransactionData

type TransactionData struct {
	Content    []byte
	Code       []byte
	Ledger     Ledger
	Ownerships []Ownership
	Recipients []Recipient
}

type TransactionErrorGQL

type TransactionErrorGQL struct {
	Context ErrorContext
	Reason  string
}

type TransactionOwnershipsGQL

type TransactionOwnershipsGQL struct {
	Transaction struct {
		Data struct {
			Ownerships []OwnershipGQL
		}
	} `graphql:"transaction(address: $address)"`
}

type TransactionSender

type TransactionSender struct {
	// contains filtered or unexported fields
}

func NewTransactionSender

func NewTransactionSender(client *APIClient) *TransactionSender

func (*TransactionSender) AddOnConfirmation

func (ts *TransactionSender) AddOnConfirmation(handler func(nbConfirmations, maxConfirmations int))

func (*TransactionSender) AddOnError

func (ts *TransactionSender) AddOnError(handler func(senderContext string, message error))

func (*TransactionSender) AddOnFullConfirmation

func (ts *TransactionSender) AddOnFullConfirmation(handler func(maxConfirmations int))

func (*TransactionSender) AddOnRequiredConfirmation

func (ts *TransactionSender) AddOnRequiredConfirmation(handler func(nbConfirmations int))

func (*TransactionSender) AddOnSent

func (ts *TransactionSender) AddOnSent(handler func())

func (*TransactionSender) AddOnTimeout

func (ts *TransactionSender) AddOnTimeout(handler func(nbConfirmationReceived int))

func (*TransactionSender) SendTransaction

func (ts *TransactionSender) SendTransaction(tx *TransactionBuilder, confirmationThreshold, timeout int) error

func (*TransactionSender) SubscribeTransactionConfirmed

func (ts *TransactionSender) SubscribeTransactionConfirmed(transactionAddress string, readyHandler func(), handler func(TransactionConfirmedGQL))

func (*TransactionSender) SubscribeTransactionError

func (ts *TransactionSender) SubscribeTransactionError(transactionAddress string, readyHandler func(), handler func(TransactionErrorGQL))

func (*TransactionSender) Unsubscribe

func (ts *TransactionSender) Unsubscribe(event string) error

type TransactionType

type TransactionType uint8

func (TransactionType) String

func (t TransactionType) String() (string, error)

type UcoLedger

type UcoLedger struct {
	Transfers []UcoTransfer
}

type UcoTransfer

type UcoTransfer struct {
	To     []byte
	Amount uint64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL