crypto

package
v0.0.0-...-ecd43bb Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CONFIG_NETWORK = &Network{}
	CONFIG_FEES    = []FlexToshi{
		TRANSACTION_FEES.Transfer,
		TRANSACTION_FEES.SecondSignatureRegistration,
		TRANSACTION_FEES.DelegateRegistration,
		TRANSACTION_FEES.Vote,
		TRANSACTION_FEES.MultiSignatureRegistration,
		TRANSACTION_FEES.Ipfs,
		TRANSACTION_FEES.TimelockTransfer,
		TRANSACTION_FEES.MultiPayment,
		TRANSACTION_FEES.DelegateResignation,
	}
)
View Source
var (
	TRANSACTION_TYPES = &TransactionTypes{
		Transfer:                    0,
		SecondSignatureRegistration: 1,
		DelegateRegistration:        2,
		Vote:                        3,
		MultiSignatureRegistration:  4,
		Ipfs:                        5,
		TimelockTransfer:            6,
		MultiPayment:                7,
		DelegateResignation:         8,
	}
	TRANSACTION_FEES = &TransactionFees{
		Transfer:                    10000000,
		SecondSignatureRegistration: 500000000,
		DelegateRegistration:        2500000000,
		Vote:                        100000000,
		MultiSignatureRegistration:  500000000,
		Ipfs:                        0,
		TimelockTransfer:            0,
		MultiPayment:                0,
		DelegateResignation:         0,
	}
)
View Source
var (
	NETWORKS_MAINNET = &Network{
		Epoch:   time.Date(2017, 3, 21, 13, 00, 0, 0, time.UTC),
		Version: 23,
		Wif:     170,
	}
	NETWORKS_DEVNET = &Network{
		Epoch:   time.Date(2017, 3, 21, 13, 00, 0, 0, time.UTC),
		Version: 30,
		Wif:     170,
	}
	NETWORKS_TESTNET = &Network{
		Epoch:   time.Date(2017, 3, 21, 13, 00, 0, 0, time.UTC),
		Version: 23,
		Wif:     186,
	}
)

Functions

func AddressFromPassphrase

func AddressFromPassphrase(passphrase string) (string, error)

func AddressToBytes

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

func Base58Decode

func Base58Decode(data string) []byte

func Base58Encode

func Base58Encode(data []byte) string

func Byte2Hex

func Byte2Hex(data byte) string

func GetEpoch

func GetEpoch() uint32

func GetFixture

func GetFixture(file string) string

func GetTime

func GetTime() int32

func GetTransactionFixture

func GetTransactionFixture(transactionType string, file string) string

func Hex2Byte

func Hex2Byte(data []byte) string

func HexDecode

func HexDecode(data string) []byte

func HexEncode

func HexEncode(data []byte) string

func SerialiseTransaction

func SerialiseTransaction(transaction *Transaction) []byte

func SetFee

func SetFee(transactionType byte, value FlexToshi)

func SetNetwork

func SetNetwork(network *Network)

func ValidateAddress

func ValidateAddress(address string) (bool, error)

Types

type DelegateAsset

type DelegateAsset struct {
	Username string `json:"username,omitempty"`
}

type FlexToshi

type FlexToshi uint64

func GetFee

func GetFee(transactionType byte) FlexToshi

func (*FlexToshi) UnmarshalJSON

func (fi *FlexToshi) UnmarshalJSON(b []byte) error

type IpfsAsset

type IpfsAsset struct {
	Dag string `json:"dag,omitempty"`
}

type Message

type Message struct {
	Message   string `json:"message"`
	PublicKey string `json:"publickey"`
	Signature string `json:"signature"`
}

func SignMessage

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

func (*Message) ToJson

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

func (*Message) ToMap

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

func (*Message) Verify

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

type MultiPaymentAsset

type MultiPaymentAsset struct {
	Amount      FlexToshi `json:"amount,omitempty"`
	RecipientId string    `json:"recipientId,omitempty"`
}

type MultiSignatureRegistrationAsset

type MultiSignatureRegistrationAsset struct {
	Min       byte     `json:"min,omitempty"`
	Keysgroup []string `json:"keysgroup,omitempty"`
	Lifetime  byte     `json:"lifetime,omitempty"`
}

type Network

type Network struct {
	Epoch   time.Time
	Version byte
	Wif     byte
}

func GetNetwork

func GetNetwork() *Network

type PrivateKey

type PrivateKey struct {
	*btcec.PrivateKey
	PublicKey *PublicKey
}

func PrivateKeyFromBytes

func PrivateKeyFromBytes(bytes []byte) *PrivateKey

func PrivateKeyFromHex

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

func PrivateKeyFromPassphrase

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

func (*PrivateKey) Sign

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

func (*PrivateKey) ToAddress

func (privateKey *PrivateKey) ToAddress() string

func (*PrivateKey) ToHex

func (privateKey *PrivateKey) ToHex() string

func (*PrivateKey) ToWif

func (privateKey *PrivateKey) ToWif() string

type PublicKey

type PublicKey struct {
	*btcec.PublicKey

	Network *Network
	// contains filtered or unexported fields
}

func PublicKeyFromBytes

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

func PublicKeyFromHex

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

func PublicKeyFromPassphrase

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

func (*PublicKey) AddressBytes

func (publicKey *PublicKey) AddressBytes() []byte

func (*PublicKey) Serialize

func (publicKey *PublicKey) Serialize() []byte

func (*PublicKey) ToAddress

func (publicKey *PublicKey) ToAddress() string

func (*PublicKey) ToHex

func (publicKey *PublicKey) ToHex() string

func (*PublicKey) Verify

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

type SecondSignatureRegistrationAsset

type SecondSignatureRegistrationAsset struct {
	PublicKey string `json:"publicKey,omitempty"`
}

type TestingDelegateRegistrationFixture

type TestingDelegateRegistrationFixture struct {
	Data struct {
		Type            uint8     `json:"type,omitempty"`
		Network         uint8     `json:"network,omitempty"`
		Version         uint8     `json:"version,omitempty"`
		Amount          FlexToshi `json:"amount,omitempty"`
		Fee             FlexToshi `json:"fee,omitempty"`
		RecipientId     string    `json:"recipientId,omitempty"`
		Timestamp       int32     `json:"timestamp,omitempty"`
		SenderPublicKey string    `json:"senderPublicKey,omitempty"`
		Signature       string    `json:"signature,omitempty"`
		Id              string    `json:"id,omitempty"`
		Asset           struct {
			Delegate DelegateAsset `json:"delegate,omitempty"`
		} `json:"asset,omitempty"`
	} `json:"data,omitempty"`
	Serialized string `json:"serialized,omitempty"`
}

type TestingIdentityFixture

type TestingIdentityFixture struct {
	Data struct {
		PrivateKey string `json:"privateKey,omitempty"`
		PublicKey  string `json:"publicKey,omitempty"`
		Address    string `json:"address,omitempty"`
		WIF        string `json:"wif,omitempty"`
	} `json:"data,omitempty"`
	Passphrase string `json:"passphrase,omitempty"`
}

func GetIdentityFixture

func GetIdentityFixture() TestingIdentityFixture

type TestingMessageFixture

type TestingMessageFixture struct {
	Data struct {
		PublicKey string `json:"publickey,omitempty"`
		Signature string `json:"signature,omitempty"`
		Message   string `json:"message,omitempty"`
	} `json:"data,omitempty"`
	Passphrase string `json:"passphrase,omitempty"`
}

func GetMessageFixture

func GetMessageFixture() TestingMessageFixture

type TestingMultiSignatureRegistrationFixture

type TestingMultiSignatureRegistrationFixture struct {
	Data struct {
		Type            uint8     `json:"type,omitempty"`
		Network         uint8     `json:"network,omitempty"`
		Version         uint8     `json:"version,omitempty"`
		Amount          FlexToshi `json:"amount,omitempty"`
		Fee             FlexToshi `json:"fee,omitempty"`
		RecipientId     string    `json:"recipientId,omitempty"`
		Timestamp       int32     `json:"timestamp,omitempty"`
		SenderPublicKey string    `json:"senderPublicKey,omitempty"`
		Signature       string    `json:"signature,omitempty"`
		SignSignature   string    `json:"signSignature,omitempty"`
		Id              string    `json:"id,omitempty"`
		Signatures      []string  `json:"signatures,omitempty"`
		Asset           struct {
			MultiSignature MultiSignatureRegistrationAsset `json:"multisignature,omitempty"`
		} `json:"asset,omitempty"`
	} `json:"data,omitempty"`
	Serialized string `json:"serialized,omitempty"`
}

type TestingSecondSignatureRegistrationFixture

type TestingSecondSignatureRegistrationFixture struct {
	Data struct {
		Type            uint8     `json:"type,omitempty"`
		Network         uint8     `json:"network,omitempty"`
		Version         uint8     `json:"version,omitempty"`
		Amount          FlexToshi `json:"amount,omitempty"`
		Fee             FlexToshi `json:"fee,omitempty"`
		RecipientId     string    `json:"recipientId,omitempty"`
		Timestamp       int32     `json:"timestamp,omitempty"`
		SenderPublicKey string    `json:"senderPublicKey,omitempty"`
		Signature       string    `json:"signature,omitempty"`
		Id              string    `json:"id,omitempty"`
		Asset           struct {
			Signature SecondSignatureRegistrationAsset `json:"signature,omitempty"`
		} `json:"asset,omitempty"`
	} `json:"data,omitempty"`
	Serialized string `json:"serialized,omitempty"`
}

type TestingTransferFixture

type TestingTransferFixture struct {
	Data struct {
		Type            uint8     `json:"type,omitempty"`
		Network         uint8     `json:"network,omitempty"`
		Version         uint8     `json:"version,omitempty"`
		Amount          FlexToshi `json:"amount,omitempty"`
		Fee             FlexToshi `json:"fee,omitempty"`
		RecipientId     string    `json:"recipientId,omitempty"`
		Timestamp       int32     `json:"timestamp,omitempty"`
		SenderPublicKey string    `json:"senderPublicKey,omitempty"`
		Signature       string    `json:"signature,omitempty"`
		Id              string    `json:"id,omitempty"`
		VendorFieldHex  string    `json:"vendorFieldHex,omitempty"`
	} `json:"data,omitempty"`
	Serialized string `json:"serialized,omitempty"`
}

type TestingVoteFixture

type TestingVoteFixture struct {
	Data struct {
		Type            uint8     `json:"type,omitempty"`
		Network         uint8     `json:"network,omitempty"`
		Version         uint8     `json:"version,omitempty"`
		Amount          FlexToshi `json:"amount,omitempty"`
		Fee             FlexToshi `json:"fee,omitempty"`
		RecipientId     string    `json:"recipientId,omitempty"`
		Timestamp       int32     `json:"timestamp,omitempty"`
		SenderPublicKey string    `json:"senderPublicKey,omitempty"`
		Signature       string    `json:"signature,omitempty"`
		Id              string    `json:"id,omitempty"`
		Asset           struct {
			Votes []string `json:"votes,omitempty"`
		} `json:"asset,omitempty"`
	} `json:"data,omitempty"`
	Serialized string `json:"serialized,omitempty"`
}

type Transaction

type Transaction struct {
	Amount                FlexToshi         `json:"amount,omitempty"`
	Asset                 *TransactionAsset `json:"asset,omitempty"`
	Expiration            uint32            `json:"expiration,omitempty"`
	Fee                   FlexToshi         `json:"fee,omitempty"`
	Id                    string            `json:"id,omitempty"`
	Network               byte              `json:"network,omitempty"`
	RecipientId           string            `json:"recipientId,omitempty"`
	SecondSenderPublicKey string            `json:"secondSenderPublicKey,omitempty"`
	SecondSignature       string            `json:"secondSignature,omitempty"`
	SenderPublicKey       string            `json:"senderPublicKey,omitempty"`
	Serialized            string            `json:"serialized,omitempty"`
	Signature             string            `json:"signature,omitempty"`
	Signatures            []string          `json:"signatures,omitempty"`
	SignSignature         string            `json:"signSignature,omitempty"`
	Timelock              uint32            `json:"timelock,omitempty"`
	TimelockType          string            `json:"timelockType,omitempty"`
	Timestamp             int32             `json:"timestamp,omitempty"`
	Type                  byte              `json:"type"`
	VendorField           string            `json:"vendorField,omitempty"`
	VendorFieldHex        string            `json:"vendorFieldHex,omitempty"`
	Version               byte              `json:"version,omitempty"`
}

func BuildDelegateRegistration

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

func BuildMultiSignatureRegistration

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

func BuildSecondSignatureRegistration

func BuildSecondSignatureRegistration(passphrase string, secondPassphrase string) *Transaction

func BuildTransfer

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

func BuildVote

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

func DeserializeTransaction

func DeserializeTransaction(serialized string) *Transaction

func (*Transaction) GetId

func (transaction *Transaction) GetId() string

func (*Transaction) ParseSignatures

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

func (*Transaction) SecondSign

func (transaction *Transaction) SecondSign(passphrase string)

func (*Transaction) SecondVerify

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

func (*Transaction) Serialize

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

func (*Transaction) Sign

func (transaction *Transaction) Sign(passphrase string)

func (*Transaction) ToBytes

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

func (*Transaction) ToJson

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

func (*Transaction) ToMap

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

func (*Transaction) Verify

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

type TransactionAsset

type TransactionAsset struct {
	Votes          []string                          `json:"votes,omitempty"`
	Dag            string                            `json:"dag,omitempty"`
	Signature      *SecondSignatureRegistrationAsset `json:"signature,omitempty"`
	Delegate       *DelegateAsset                    `json:"delegate,omitempty"`
	MultiSignature *MultiSignatureRegistrationAsset  `json:"multisignature,omitempty"`
	Ipfs           *IpfsAsset                        `json:"ipfs,omitempty"`
	Payments       []*MultiPaymentAsset              `json:"payments,omitempty"`
}

type TransactionFees

type TransactionFees struct {
	Transfer                    FlexToshi
	SecondSignatureRegistration FlexToshi
	DelegateRegistration        FlexToshi
	Vote                        FlexToshi
	MultiSignatureRegistration  FlexToshi
	Ipfs                        FlexToshi
	TimelockTransfer            FlexToshi
	MultiPayment                FlexToshi
	DelegateResignation         FlexToshi
}

type TransactionTypes

type TransactionTypes struct {
	Transfer                    byte
	SecondSignatureRegistration byte
	DelegateRegistration        byte
	Vote                        byte
	MultiSignatureRegistration  byte
	Ipfs                        byte
	TimelockTransfer            byte
	MultiPayment                byte
	DelegateResignation         byte
}

Directories

Path Synopsis
Package base58 implements a human-friendly base58 encoding.
Package base58 implements a human-friendly base58 encoding.

Jump to

Keyboard shortcuts

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