mixinnet

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 26 Imported by: 17

Documentation

Index

Constants

View Source
const (
	MinimumEncodingVersion = 0x1
	MaximumEncodingInt     = 0xFFFF

	AggregatedSignaturePrefix      = 0xFF01
	AggregatedSignatureSparseMask  = byte(0x01)
	AggregatedSignatureOrdinayMask = byte(0x00)
)
View Source
const (
	InvalidOutputKey = 2000001
	InputLocked      = 2000002
	InvalidSignature = 2000003
)

mixin error codes https://developers.mixin.one/api/alpha-mixin-network/errors/

View Source
const (
	TxMethodSend    = "sendrawtransaction"
	TxMethodGet     = "gettransaction"
	TxMethodGetUtxo = "getutxo"
)
View Source
const (
	TxVersionCommonEncoding = 0x02
	TxVersionBlake3Hash     = 0x03
	TxVersionReferences     = 0x04
	TxVersionHashSignature  = 0x05

	TxVersionLegacy = TxVersionReferences
	TxVersion       = TxVersionHashSignature
)
View Source
const (
	OutputTypeScript           = 0x00
	OutputTypeWithdrawalSubmit = 0xa1
	OutputTypeWithdrawalFuel   = 0xa2
	OutputTypeNodePledge       = 0xa3
	OutputTypeNodeAccept       = 0xa4

	OutputTypeNodeRemove          = 0xa6
	OutputTypeDomainAccept        = 0xa7
	OutputTypeDomainRemove        = 0xa8
	OutputTypeWithdrawalClaim     = 0xa9
	OutputTypeNodeCancel          = 0xaa
	OutputTypeCustodianEvolution  = 0xb1
	OutputTypeCustodianMigration  = 0xb2
	OutputTypeCustodianDeposit    = 0xb3
	OutputTypeCustodianWithdrawal = 0xb4
)
View Source
const (
	TransactionTypeScript           = 0x00
	TransactionTypeMint             = 0x01
	TransactionTypeDeposit          = 0x02
	TransactionTypeWithdrawalSubmit = 0x03
	TransactionTypeWithdrawalFuel   = 0x04
	TransactionTypeWithdrawalClaim  = 0x05
	TransactionTypeNodePledge       = 0x06
	TransactionTypeNodeAccept       = 0x07

	TransactionTypeNodeRemove           = 0x09
	TransactionTypeDomainAccept         = 0x10
	TransactionTypeDomainRemove         = 0x11
	TransactionTypeNodeCancel           = 0x12
	TransactionTypeCustodianUpdateNodes = 0x13
	TransactionTypeCustodianSlashNodes  = 0x14
	TransactionTypeUnknown              = 0xff
)
View Source
const (
	Operator0   = 0x00
	Operator64  = 0x40
	OperatorSum = 0xfe
	OperatorCmp = 0xff
)
View Source
const (
	ExtraSizeGeneralLimit    = 256
	ExtraSizeStorageStep     = 1024
	ExtraSizeStorageCapacity = 1024 * 1024 * 4
	ExtraStoragePriceStep    = "0.001"
	SliceCountLimit          = 256
	ReferencesCountLimit     = 2
)
View Source
const MainNetworkID = "XIN"
View Source
const Precision = 8

Variables

View Source
var (
	DefaultLegacyConfig = Config{
		Safe:  false,
		Hosts: legacyHosts,
	}
	DefaultSafeConfig = Config{
		Safe:  true,
		Hosts: safeHosts,
	}
)

Functions

func DecodeResponse

func DecodeResponse(resp *http.Response) ([]byte, error)

func GenerateEd25519Key

func GenerateEd25519Key() ed25519.PrivateKey

func HashMembers

func HashMembers(ids []string) string

func HashScalar

func HashScalar(txVer uint8, k *edwards25519.Point, outputIndex uint8) *edwards25519.Scalar

func IsErrorCodes

func IsErrorCodes(err error, codes ...int) bool

func KeyMultPubPriv

func KeyMultPubPriv(pub, priv *Key) *edwards25519.Point

func UnmarshalResponse

func UnmarshalResponse(resp *http.Response, v interface{}) error

Types

type Address

type Address struct {
	PrivateSpendKey Key `json:"private_spend_key"`
	PrivateViewKey  Key `json:"private_view_key"`
	PublicSpendKey  Key `json:"public_spend_key"`
	PublicViewKey   Key `json:"public_view_key"`
}

func AddressFromPublicSpend

func AddressFromPublicSpend(publicSpend Key) *Address

func AddressFromString

func AddressFromString(s string) (Address, error)

func GenerateAddress

func GenerateAddress(rand io.Reader, public ...bool) *Address

func (Address) CreateUTXO

func (a Address) CreateUTXO(txVer uint8, outputIndex uint8, amount decimal.Decimal) *Output

func (Address) Hash

func (a Address) Hash() Hash

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

func (Address) String

func (a Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

type AggregatedSignature

type AggregatedSignature struct {
	Signers   []int      `json:"signers"`
	Signature *Signature `json:"signature"`
}

type Client

type Client struct {
	http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg Config) *Client

func (*Client) CallMixinNetRPC

func (c *Client) CallMixinNetRPC(ctx context.Context, resp interface{}, method string, params ...interface{}) error

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, hash Hash) (*Transaction, error)

func (*Client) GetUTXO

func (c *Client) GetUTXO(ctx context.Context, hash Hash, outputIndex uint8) (*UTXO, error)

func (*Client) HostFromContext

func (c *Client) HostFromContext(ctx context.Context) string

func (*Client) RandomHost

func (c *Client) RandomHost() string

func (*Client) ReadConsensusInfo

func (c *Client) ReadConsensusInfo(ctx context.Context) (*ConsensusInfo, error)

func (*Client) SendRawTransaction

func (c *Client) SendRawTransaction(ctx context.Context, raw string) (*Transaction, error)

func (*Client) VerifyTransaction

func (c *Client) VerifyTransaction(ctx context.Context, addr *Address, txHash Hash) (bool, error)

检查 transaction 是否是由该主网地址签发。满足以下所有条件则返回 true:

  1. 所有 input 对应的 utxo 只有一个 keys, 即 不是多签地址 转出
  2. 该 input 的 mask & keys 可以使用该地址的 private view 和 public spend 碰撞通过

func (*Client) WithHost

func (c *Client) WithHost(ctx context.Context, host string) context.Context

type Config

type Config struct {
	Safe  bool
	Hosts []string
}

type ConsensusInfo

type ConsensusInfo struct {
	Network   Hash      `json:"network"`
	Node      Hash      `json:"node"`
	Version   string    `json:"version"`
	Uptime    string    `json:"uptime"`
	Epoch     time.Time `json:"epoch"`
	Timestamp time.Time `json:"timestamp"`
	Mint      Mint      `json:"mint"`
	Queue     Queue     `json:"queue"`
	Graph     Graph     `json:"graph"`
}

type ConsensusNode

type ConsensusNode struct {
	Node        Hash      `json:"node"`
	Signer      Address   `json:"signer"`
	Payee       Address   `json:"payee"`
	State       string    `json:"state"`
	Timestamp   int64     `json:"timestamp"`
	Transaction Hash      `json:"transaction"`
	Aggregator  uint64    `json:"aggregator"`
	Works       [2]uint64 `json:"works"`
}

type Decoder

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

func NewDecoder

func NewDecoder(b []byte) *Decoder

func NewMinimumDecoder

func NewMinimumDecoder(b []byte) (*Decoder, error)

func (*Decoder) DecodeTransaction

func (dec *Decoder) DecodeTransaction() (*Transaction, error)

func (*Decoder) Read

func (dec *Decoder) Read(b []byte) error

func (*Decoder) ReadAggregatedSignature

func (dec *Decoder) ReadAggregatedSignature() (*AggregatedSignature, error)

func (*Decoder) ReadByte

func (dec *Decoder) ReadByte() (byte, error)

func (*Decoder) ReadBytes

func (dec *Decoder) ReadBytes() ([]byte, error)

func (*Decoder) ReadInput

func (dec *Decoder) ReadInput() (*Input, error)

func (*Decoder) ReadInt

func (dec *Decoder) ReadInt() (int, error)

func (*Decoder) ReadInteger

func (dec *Decoder) ReadInteger() (Integer, error)

func (*Decoder) ReadMagic

func (dec *Decoder) ReadMagic() (bool, error)

func (*Decoder) ReadOutput

func (dec *Decoder) ReadOutput(ver uint8) (*Output, error)

func (*Decoder) ReadSignatures

func (dec *Decoder) ReadSignatures() (map[uint16]*Signature, error)

func (*Decoder) ReadUint16

func (dec *Decoder) ReadUint16() (uint16, error)

func (*Decoder) ReadUint32

func (dec *Decoder) ReadUint32() (uint32, error)

func (*Decoder) ReadUint64

func (dec *Decoder) ReadUint64() (uint64, error)

type DepositData

type DepositData struct {
	Chain       Hash    `json:"chain"`
	AssetKey    string  `json:"asset"`
	Transaction string  `json:"transaction"`
	Index       uint64  `json:"index"`
	Amount      Integer `json:"amount"`
}

type Encoder

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

func NewEncoder

func NewEncoder() *Encoder

func NewMinimumEncoder

func NewMinimumEncoder() *Encoder

func (*Encoder) EncodeAggregatedSignature

func (enc *Encoder) EncodeAggregatedSignature(js *AggregatedSignature)

func (*Encoder) EncodeInput

func (enc *Encoder) EncodeInput(in *Input)

func (*Encoder) EncodeOutput

func (enc *Encoder) EncodeOutput(o *Output, ver uint8)

func (*Encoder) EncodeSignatures

func (enc *Encoder) EncodeSignatures(sm map[uint16]*Signature)

func (*Encoder) EncodeTransaction

func (enc *Encoder) EncodeTransaction(signed *Transaction) []byte

func (*Encoder) Write

func (enc *Encoder) Write(b []byte)

func (*Encoder) WriteByte

func (enc *Encoder) WriteByte(b byte) error

func (*Encoder) WriteInt

func (enc *Encoder) WriteInt(d int)

func (*Encoder) WriteInteger

func (enc *Encoder) WriteInteger(d Integer)

func (*Encoder) WriteUint16

func (enc *Encoder) WriteUint16(d uint16)

func (*Encoder) WriteUint32

func (enc *Encoder) WriteUint32(d uint32)

func (*Encoder) WriteUint64

func (enc *Encoder) WriteUint64(d uint64)

type Error

type Error struct {
	Status      int                    `json:"status"`
	Code        int                    `json:"code"`
	Description string                 `json:"description"`
	Extra       map[string]interface{} `json:"extra,omitempty"`
	RequestID   string                 `json:"request_id,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type Graph

type Graph struct {
	SPS       float64                `json:"sps"`
	Topology  uint64                 `json:"topology"`
	Consensus []*ConsensusNode       `json:"consensus"`
	Final     map[string]*GraphFinal `json:"final"`
	Cache     map[string]*GraphCache `json:"cache"`
}

type GraphCache

type GraphCache struct {
	Node       Hash             `json:"node"`
	References GraphReferences  `json:"references"`
	Timestamp  int64            `json:"timestamp"`
	Round      uint64           `json:"round"`
	Snapshots  []*GraphSnapshot `json:"snapshots"`
}

type GraphFinal

type GraphFinal struct {
	Node  Hash   `json:"node"`
	Hash  Hash   `json:"hash"`
	Start int64  `json:"start"`
	End   int64  `json:"end"`
	Round uint64 `json:"round"`
}

type GraphReferences

type GraphReferences struct {
	External Hash `json:"external"`
	Self     Hash `json:"self"`
}

type GraphSnapshot

type GraphSnapshot struct {
	Node        Hash            `json:"node"`
	Hash        Hash            `json:"hash"`
	References  GraphReferences `json:"references"`
	Round       uint64          `json:"round"`
	Timestamp   int64           `json:"timestamp"`
	Transaction Hash            `json:"transaction"`
	Signature   string          `json:"signature"` // CosiSignature
	Version     int             `json:"version"`
}

type Hash

type Hash [32]byte
var (
	XINAssetId Hash
)

func HashFromString

func HashFromString(src string) (Hash, error)

func NewBlake3Hash

func NewBlake3Hash(data []byte) Hash

func NewHash

func NewHash(data []byte) Hash

func (Hash) HasValue

func (h Hash) HasValue() bool

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(b []byte) error

type Input

type Input struct {
	Hash    *Hash        `json:"hash,omitempty"`
	Index   uint8        `json:"index,omitempty"`
	Genesis []byte       `json:"genesis,omitempty"`
	Deposit *DepositData `json:"deposit,omitempty"`
	Mint    *MintData    `json:"mint,omitempty"`
}

type InputUTXO

type InputUTXO struct {
	Input

	Asset  Hash            `json:"asset"`
	Amount decimal.Decimal `json:"amount,omitempty"`
}

type Integer

type Integer struct {
	// contains filtered or unexported fields
}
var Zero Integer

func IntegerFromDecimal

func IntegerFromDecimal(d decimal.Decimal) (v Integer)

func IntegerFromString

func IntegerFromString(x string) (v Integer)

func NewInteger

func NewInteger(x uint64) (v Integer)

func (Integer) Add

func (x Integer) Add(y Integer) (v Integer)

func (Integer) Cmp

func (x Integer) Cmp(y Integer) int

func (Integer) Count

func (x Integer) Count(y Integer) uint64

func (Integer) Div

func (x Integer) Div(y int) (v Integer)

func (Integer) MarshalJSON

func (x Integer) MarshalJSON() ([]byte, error)

func (Integer) MarshalMsgpack

func (x Integer) MarshalMsgpack() ([]byte, error)

func (Integer) Mul

func (x Integer) Mul(y int) (v Integer)

func (Integer) Sign

func (x Integer) Sign() int

func (Integer) String

func (x Integer) String() string

func (Integer) Sub

func (x Integer) Sub(y Integer) (v Integer)

func (*Integer) UnmarshalJSON

func (x *Integer) UnmarshalJSON(b []byte) error

func (*Integer) UnmarshalMsgpack

func (x *Integer) UnmarshalMsgpack(data []byte) error

type Key

type Key [32]byte

func DeriveGhostPrivateKey

func DeriveGhostPrivateKey(txVer uint8, R, a, b *Key, outputIndex uint8) *Key

func DeriveGhostPublicKey

func DeriveGhostPublicKey(txVer uint8, r, A, B *Key, outputIndex uint8) *Key

func GenerateKey

func GenerateKey(randReader io.Reader) Key

func KeyFromBytes added in v2.0.4

func KeyFromBytes(bts []byte) Key

func KeyFromSeed

func KeyFromSeed(seed string) (Key, error)

func KeyFromString

func KeyFromString(s string) (Key, error)

func ParseKeyWithPub added in v2.0.4

func ParseKeyWithPub(s, pub string) (Key, error)

func ViewGhostOutputKey

func ViewGhostOutputKey(txVer uint8, P, a, R *Key, outputIndex uint8) *Key

func (Key) CheckKey

func (k Key) CheckKey() bool

func (Key) DeterministicHashDerive

func (k Key) DeterministicHashDerive() Key

func (Key) HasValue

func (k Key) HasValue() bool

func (Key) MarshalJSON

func (k Key) MarshalJSON() ([]byte, error)

func (Key) Public

func (k Key) Public() Key

func (*Key) Sign

func (privateKey *Key) Sign(message []byte) Signature

func (*Key) SignHash

func (privateKey *Key) SignHash(h Hash) Signature

func (Key) String

func (k Key) String() string

func (Key) ToPoint

func (k Key) ToPoint() (*edwards25519.Point, error)

func (Key) ToScalar

func (k Key) ToScalar() (*edwards25519.Scalar, error)

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(b []byte) error

func (*Key) Verify

func (publicKey *Key) Verify(message []byte, sig Signature) bool

func (*Key) VerifyHash

func (publicKey *Key) VerifyHash(message Hash, sig Signature) bool

func (*Key) VerifyWithChallenge

func (publicKey *Key) VerifyWithChallenge(sig Signature, a *edwards25519.Scalar) bool

type Mint

type Mint struct {
	Pool   decimal.Decimal `json:"pool"`
	Pledge decimal.Decimal `json:"pledge"`
	Batch  uint64          `json:"batch"`
}

type MintData

type MintData struct {
	Group  string  `json:"group"`
	Batch  uint64  `json:"batch"`
	Amount Integer `json:"amount"`
}

type Output

type Output struct {
	Type       uint8           `json:"type"`
	Amount     Integer         `json:"amount"`
	Keys       []Key           `json:"keys,omitempty"`
	Withdrawal *WithdrawalData `json:"withdrawal,omitempty" msgpack:",omitempty"`

	Script Script `json:"script"`
	Mask   Key    `json:"mask,omitempty"`
}

type Queue

type Queue struct {
	Finals uint64 `json:"finals"`
	Caches uint64 `json:"caches"`
}

type Script

type Script []uint8

func NewThresholdScript

func NewThresholdScript(threshold uint8) Script

func (Script) MarshalJSON

func (s Script) MarshalJSON() ([]byte, error)

func (Script) String

func (s Script) String() string

func (*Script) UnmarshalJSON

func (s *Script) UnmarshalJSON(b []byte) error

func (Script) Validate

func (s Script) Validate(sum int) error

func (Script) VerifyFormat

func (s Script) VerifyFormat() error

type Signature

type Signature [64]byte

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

func (Signature) String

func (s Signature) String() string

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(b []byte) error

type Transaction

type Transaction struct {
	Hash                *Hash                   `json:"hash,omitempty" msgpack:"-"`
	Snapshot            *Hash                   `json:"snapshot,omitempty" msgpack:"-"`
	Signatures          []map[uint16]*Signature `json:"signatures,omitempty" msgpack:"-"`
	AggregatedSignature *AggregatedSignature    `json:"aggregated_signature,omitempty" msgpack:"-"`

	Version    uint8            `json:"version"`
	Asset      Hash             `json:"asset"`
	Inputs     []*Input         `json:"inputs"`
	Outputs    []*Output        `json:"outputs"`
	References []Hash           `msgpack:"-"`
	Extra      TransactionExtra `json:"extra,omitempty"`
}

func TransactionFromData

func TransactionFromData(data []byte) (*Transaction, error)

func TransactionFromRaw

func TransactionFromRaw(raw string) (*Transaction, error)

func (*Transaction) Dump

func (t *Transaction) Dump() (string, error)

func (*Transaction) DumpData

func (t *Transaction) DumpData() ([]byte, error)

func (Transaction) DumpPayload

func (t Transaction) DumpPayload() ([]byte, error)

func (*Transaction) ExtraLimit

func (tx *Transaction) ExtraLimit() int

func (*Transaction) TransactionHash

func (t *Transaction) TransactionHash() (Hash, error)

type TransactionExtra

type TransactionExtra []byte

func (TransactionExtra) MarshalJSON

func (e TransactionExtra) MarshalJSON() ([]byte, error)

func (TransactionExtra) String

func (e TransactionExtra) String() string

func (*TransactionExtra) UnmarshalJSON

func (e *TransactionExtra) UnmarshalJSON(b []byte) error

type TransactionInput

type TransactionInput struct {
	TxVersion  uint8
	Memo       string
	Inputs     []*InputUTXO
	Outputs    []*Output
	References []Hash
	Hint       string
}

func (*TransactionInput) Asset

func (input *TransactionInput) Asset() Hash

func (*TransactionInput) Build

func (input *TransactionInput) Build() (*Transaction, error)

func (*TransactionInput) TotalInputAmount

func (input *TransactionInput) TotalInputAmount() decimal.Decimal

func (*TransactionInput) Validate

func (input *TransactionInput) Validate() error

type TransactionV1

type TransactionV1 struct {
	Transaction
	Signatures [][]*Signature `json:"signatures,omitempty" msgpack:",omitempty"`
}

func (*TransactionV1) Dump

func (t *TransactionV1) Dump() (string, error)

type UTXO

type UTXO struct {
	Type   uint8           `json:"type"`
	Amount decimal.Decimal `json:"amount"`
	Hash   Hash            `json:"hash"`
	Index  uint8           `json:"index,omitempty"`
	Lock   *Hash           `json:"lock,omitempty"`
}

type WithdrawalData

type WithdrawalData struct {
	Address string `json:"address"`
	Tag     string `json:"tag"`

	// DEPRECATED since safe, tx 5, TxVersionHashSignature
	Chain Hash `json:"chain"`
	// DEPRECATED since safe, tx 5, TxVersionHashSignature
	AssetKey string `json:"asset"`
}

Jump to

Keyboard shortcuts

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