hxnet

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: LGPL-3.0 Imports: 15 Imported by: 9

README

hxnet-sdk

Hengxin Network SDK

Documentation

Index

Constants

View Source
const (
	Operator0   = 0x00
	Operator64  = 0x40
	OperatorSum = 0xfe
	OperatorCmp = 0xff
)
View Source
const HXKeyStore = "HXKS"
View Source
const HXNetwork = "HX"

Symobl

Variables

View Source
var (
	ErrSigVerification = errors.New(errMsgVerificationFailed)
)

Functions

func IsSigVerificationErr added in v0.2.1

func IsSigVerificationErr(err error) bool

Types

type Address added in v0.0.2

type Address struct {
	PrivateSpendKey   crypto.PrivateKey
	PrivateViewKey    crypto.PrivateKey
	PrivateEncryptKey crypto.EPrivateKey

	PublicSpendKey   crypto.PublicKey
	PublicViewKey    crypto.PublicKey
	PublicEncryptKey crypto.EPublicKey
}

地址数据结构,由三对密钥构成,分别为 SpendKey,ViewKey,和EncryptKey

func AddressFromKeyStone added in v0.0.2

func AddressFromKeyStone(addrStr string) (*Address, error)

通过字符串生成用户地址 字符串格式

返回地址或者错误

func AddressFromString added in v0.0.2

func AddressFromString(s string) (*Address, error)

通过字符串生成用户地址 字符串格式

返回地址或者错误

func NewAddress added in v0.0.2

func NewAddress(public ...bool) (*Address, error)

生成新的地址, 地址有3对密钥构成,分别是 Spend Key、 View Key 和 Encrypt Key

Spend Key 和 View Key 主要是在恒信的区块链网络中使用
Ecrypt Key 主要作用是用于对 数据仓库中加密数据的密钥进行密钥交换

三个密钥都不可以泄漏

func (Address) GhostPrivateKey added in v0.0.2

func (a Address) GhostPrivateKey(mask crypto.PublicKey, outputIndex uint64) crypto.PrivateKey

使用签名方的 Private SpendKey 和 ViewKey 生成用来签名 Private Key

func (Address) GhostPublicKey added in v0.0.2

func (a Address) GhostPublicKey(r crypto.PrivateKey, outputIndex uint64) crypto.PublicKey

使用接受方的 SpendKey 和 ViewKey 生成用来转账的 Public Key

func (Address) KeyStore added in v0.2.1

func (a Address) KeyStore() string

func (Address) MarshalJSON added in v0.0.2

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

生成地址的字符串

func (Address) SignJWTToken added in v0.0.2

func (a Address) SignJWTToken(typ JWTKeyType) (string, error)
{
    "iss": "HXxxxx", // 用户的Address
    "exp": 123, // 过期时间
    "iat": 123, // 当前时间
    "nc": "nonce", // 随机的nonce用于防重放
    "sig": "xxx" // 签名
}

func (Address) String added in v0.0.2

func (a Address) String() string

根据用户的地址生成对外的交易地址 地址的格式规定如下 Address: HX + Base58(Public Spend Key + Public View Key + Public EncryptKey + CRC)

func (*Address) UnmarshalJSON added in v0.0.2

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

通过字符串恢复地址 自己有公钥可用,私钥并没有什么用处

type CosiSignature added in v0.2.2

type CosiSignature struct {
	Signatures []crypto.Signature `json:"signatures,omitempty"`
	Mask       uint64             `json:"mask"`
}

type HXSingingPrivateKey added in v0.2.1

type HXSingingPrivateKey interface {
	Sign(message []byte) (*crypto.Signature, error)
}

type HXSingingPublicKey added in v0.2.1

type HXSingingPublicKey interface {
	Verify(message []byte, sig *crypto.Signature) bool
}

type Input

type Input struct {
	Hash    *crypto.Hash `json:"hash,omitempty"`
	Index   int          `json:"index"`
	Genesis []byte       `json:"-"`
	Deposit interface{}  `json:"-"`
	Mint    interface{}  `json:"-"`
}

type JWTClaim added in v0.0.2

type JWTClaim struct {
	jwt.StandardClaims

	Nonce     string   `json:"jti,omitempty"`
	Signature string   `json:"sig,omitempty"`
	Address   *Address `json:"-"`
}

func ParseJWTToken added in v0.0.2

func ParseJWTToken(typ JWTKeyType, token string) (*JWTClaim, error)

type JWTKeyType added in v0.0.2

type JWTKeyType int
const (
	JWTKeyTypeVK JWTKeyType = iota
	JWTKeyTypeSK
	JWTKeyTypeEK
)

type Output

type Output struct {
	Type   uint8          `json:"type"`
	Amount common.Integer `json:"amount"`
	Keys   []crypto.Key   `json:"keys,omitempty"`
	Script Script         `json:"script,omitempty"`
	Mask   crypto.Key     `json:"mask,omitempty"`
}

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 SigningMethodHX added in v0.2.1

type SigningMethodHX struct{}

func (SigningMethodHX) Alg added in v0.2.1

func (k SigningMethodHX) Alg() string

func (SigningMethodHX) Sign added in v0.2.1

func (k SigningMethodHX) Sign(signingString string, key interface{}) (string, error)

func (SigningMethodHX) Verify added in v0.2.1

func (k SigningMethodHX) Verify(signingString, signature string, key interface{}) error

type Snapshot

type Snapshot struct {
	Hash        string         `json:"hash"`
	Transaction *Transaction   `json:"transaction,omitempty"`
	Topology    int64          `json:"topology"`
	Timestamp   int64          `json:"timestamp"`
	Signature   *CosiSignature `json:"signature,omitempty"`
}

type Transaction

type Transaction struct {
	Hash       *crypto.Hash         `json:"hash,omitempty" msgpack:"-"`
	Version    uint8                `json:"version"`
	Asset      crypto.Hash          `json:"asset"`
	Inputs     []*Input             `json:"inputs"`
	Outputs    []*Output            `json:"outputs"`
	Extra      []byte               `json:"extra,omitempty"`
	Signatures [][]crypto.Signature `json:"signatures,omitempty" msgpack:",omitempty"`
	Snapshot   *crypto.Hash         `json:"snapshot,omitempty" msgpack:"-"`
}

func (*Transaction) MsgpackMarshal

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

func (*Transaction) MsgpackMarshalPayload

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

func (*Transaction) TransactionHash

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

type UTXO

type UTXO struct {
	Input
	Output
	Lock crypto.Hash `json:"lock,omitempty"`
}

type UTXOReader added in v0.0.2

type UTXOReader interface {
	ReadUTXO(hash crypto.Hash, index int) (*UTXO, error)
}

Directories

Path Synopsis
sm

Jump to

Keyboard shortcuts

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