crypto

package
v0.0.0-...-c1dff35 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIGNATURE_TYPE_ECDSA   = 0
	SIGNATURE_TYPE_SCHNORR = 1
)

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.MultiPayment,
		TRANSACTION_FEES.DelegateResignation,
		TRANSACTION_FEES.HtlcLock,
		TRANSACTION_FEES.HtlcClaim,
		TRANSACTION_FEES.HtlcRefund,
	}
	CONFIG_SIGNATURE_TYPE = SIGNATURE_TYPE_SCHNORR
)
View Source
var (
	TRANSACTION_TYPES = &TransactionTypes{
		Transfer:                    0,
		SecondSignatureRegistration: 1,
		DelegateRegistration:        2,
		Vote:                        3,
		MultiSignatureRegistration:  4,
		Ipfs:                        5,
		MultiPayment:                6,
		DelegateResignation:         7,
		HtlcLock:                    8,
		HtlcClaim:                   9,
		HtlcRefund:                  10,
	}
	TRANSACTION_TYPE_GROUPS = &TransactionTypeGroups{
		Test: 0,
		Core: 1,
	}
	TRANSACTION_FEES = &TransactionFees{
		Transfer:                    10000000,
		SecondSignatureRegistration: 500000000,
		DelegateRegistration:        2500000000,
		Vote:                        100000000,
		MultiSignatureRegistration:  500000000,
		Ipfs:                        500000000,
		MultiPayment:                10000000,
		DelegateResignation:         2500000000,
		HtlcLock:                    10000000,
		HtlcClaim:                   0,
		HtlcRefund:                  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 Base58CheckDecodeFatal

func Base58CheckDecodeFatal(data string) []byte

func Byte2Hex

func Byte2Hex(data byte) string

func ECDSASignatureLen

func ECDSASignatureLen(signature []byte) int

func GetEpoch

func GetEpoch() uint32

func GetFile

func GetFile(path string) string

func GetFixture

func GetFixture(file string) string

func GetTime

func GetTime() int32

func Hex2Byte

func Hex2Byte(data []byte) string

func HexDecode

func HexDecode(data string) []byte

func HexEncode

func HexEncode(data []byte) string

func SetFee

func SetFee(transactionType uint16, 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 uint16) FlexToshi

func (*FlexToshi) UnmarshalJSON

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

type HtlcClaimAsset

type HtlcClaimAsset struct {
	LockTransactionId string `json:"lockTransactionId,omitempty"`
	UnlockSecret      string `json:"unlockSecret,omitempty"`
}

type HtlcLockAsset

type HtlcLockAsset struct {
	SecretHash string                   `json:"secretHash,omitempty"`
	Expiration *HtlcLockExpirationAsset `json:"expiration,omitempty"`
}

type HtlcLockExpirationAsset

type HtlcLockExpirationAsset struct {
	Type  uint8  `json:"type,omitempty"`
	Value uint32 `json:"value,omitempty"`
}

type HtlcRefundAsset

type HtlcRefundAsset struct {
	LockTransactionId string `json:"lockTransactionId,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"`
	PublicKeys []string `json:"publicKeys,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) SignECDSA

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

func (*PrivateKey) SignSchnorr

func (privateKey *PrivateKey) SignSchnorr(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)

func (*PublicKey) VerifyECDSA

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

func (*PublicKey) VerifySchnorr

func (publicKey *PublicKey) VerifySchnorr(signature []byte, hash []byte) (bool, error)

type SecondSignatureRegistrationAsset

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

type TestingFixture

type TestingFixture struct {
	MultiSignatureAsset MultiSignatureRegistrationAsset `json:"multiSignatureAsset"`
	Transaction         Transaction                     `json:"transaction"`
	SerializedHex       string                          `json:"serializedHex"`
}

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 Transaction

type Transaction struct {
	// XXX check that all relevant fields are set in all Build*() methods
	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"`
	Nonce                 uint64            `json:"nonce,omitempty,string"`
	RecipientId           string            `json:"recipientId,omitempty"`
	SecondSenderPublicKey string            `json:"secondSenderPublicKey,omitempty"`
	SecondSignature       string            `json:"secondSignature,omitempty"`
	SenderPublicKey       string            `json:"senderPublicKey,omitempty"`
	Serialized            []byte            `json:"serialized,omitempty"`
	Signature             string            `json:"signature,omitempty"`
	Signatures            []string          `json:"signatures,omitempty"`
	Timestamp             int32             `json:"timestamp,omitempty"`
	Type                  uint16            `json:"type"`
	TypeGroup             uint32            `json:"typeGroup"`
	VendorField           string            `json:"vendorField,omitempty"`
	Version               byte              `json:"version,omitempty"`
}

func BuildDelegateRegistration

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

* Set all fields and sign a TransactionTypes.DelegateRegistration transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Delegate.Username
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildDelegateResignation

func BuildDelegateResignation(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.DelegateResignation transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildHtlcClaim

func BuildHtlcClaim(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.HtlcClaim transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Claim
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildHtlcLock

func BuildHtlcLock(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.HtlcLock transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Lock
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildHtlcRefund

func BuildHtlcRefund(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.HtlcRefund transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Refund
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildIpfs

func BuildIpfs(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.Ipfs transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Ipfs
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildMultiPayment

func BuildMultiPayment(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.MultiPayment transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Payments
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildMultiSignatureRegistration

func BuildMultiSignatureRegistration(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.MultiSignatureRegistration transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.MultiSignature
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildSecondSignatureRegistration

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

* Set all fields and sign a TransactionTypes.SecondSignatureRegistration transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildTransfer

func BuildTransfer(transaction *Transaction, passphrase string, secondPassphrase string) *Transaction

* Set all fields and sign a TransactionTypes.Transfer transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Amount
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • RecipientId
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildTransferMultiSignature

func BuildTransferMultiSignature(transaction *Transaction, signerIndex int, passphrase string) *Transaction

* Set all fields and sign a multi signature TransactionTypes.Transfer transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Amount
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • RecipientId
  • Signatures - must be an array (could be empty); a new signature will be appended to it
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func BuildVote

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

* Set all fields and sign a TransactionTypes.Vote transaction.

  • Members of the supplied transaction that must be set when calling this function:
  • Asset.Votes
  • Expiration - optional, could be 0 to designate no expiration
  • Fee - optional, if 0, then it will be set to a default fee
  • Network - optional, if 0, then it will be set to the configured network
  • Nonce
  • Timestamp - optional, if 0, then it will be set to the present time
  • VendorField - optional

func DeserializeTransaction

func DeserializeTransaction(serialized string) *Transaction

func (*Transaction) GetId

func (transaction *Transaction) GetId() string

func (*Transaction) ParseSignatures

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

func (*Transaction) ParseSignaturesECDSA

func (transaction *Transaction) ParseSignaturesECDSA(signatures []byte) *Transaction

func (*Transaction) ParseSignaturesSchnorr

func (transaction *Transaction) ParseSignaturesSchnorr(signatures []byte) *Transaction

func (*Transaction) SecondSign

func (transaction *Transaction) SecondSign(passphrase string)

func (*Transaction) SecondVerify

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

func (*Transaction) Sign

func (transaction *Transaction) Sign(passphrase string)

func (*Transaction) SignMulti

func (transaction *Transaction) SignMulti(signerIndex int, passphrase string)

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(multiSignatureAsset ...*MultiSignatureRegistrationAsset) (bool, error)

func (*Transaction) VerifyMultiSignature

func (transaction *Transaction) VerifyMultiSignature(multiSignatureAsset *MultiSignatureRegistrationAsset) (bool, error)

type TransactionAsset

type TransactionAsset struct {
	Votes          []string                          `json:"votes,omitempty"`
	Signature      *SecondSignatureRegistrationAsset `json:"signature,omitempty"`
	Delegate       *DelegateAsset                    `json:"delegate,omitempty"`
	MultiSignature *MultiSignatureRegistrationAsset  `json:"multiSignature,omitempty"`
	Ipfs           string                            `json:"ipfs,omitempty"`
	Payments       []*MultiPaymentAsset              `json:"payments,omitempty"`
	Lock           *HtlcLockAsset                    `json:"lock,omitempty"`
	Claim          *HtlcClaimAsset                   `json:"claim,omitempty"`
	Refund         *HtlcRefundAsset                  `json:"refund,omitempty"`
}

type TransactionFees

type TransactionFees struct {
	Transfer                    FlexToshi
	SecondSignatureRegistration FlexToshi
	DelegateRegistration        FlexToshi
	Vote                        FlexToshi
	MultiSignatureRegistration  FlexToshi
	Ipfs                        FlexToshi
	MultiPayment                FlexToshi
	DelegateResignation         FlexToshi
	HtlcLock                    FlexToshi
	HtlcClaim                   FlexToshi
	HtlcRefund                  FlexToshi
}

type TransactionTypeGroups

type TransactionTypeGroups struct {
	Test uint32
	Core uint32
}

type TransactionTypes

type TransactionTypes struct {
	Transfer                    uint16
	SecondSignatureRegistration uint16
	DelegateRegistration        uint16
	Vote                        uint16
	MultiSignatureRegistration  uint16
	Ipfs                        uint16
	MultiPayment                uint16
	DelegateResignation         uint16
	HtlcLock                    uint16
	HtlcClaim                   uint16
	HtlcRefund                  uint16
}

Jump to

Keyboard shortcuts

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