commons

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package bip32 provides ...

Package bip32 provides ...

Index

Constants

View Source
const (
	REWARD_TX   WaykiTxType = 1 + iota //!< reward tx
	REG_ACCT_TX                        //!< tx that used to register account
	COMMON_TX                          //!< transfer coin from one account to another
	CONTRACT_TX                        //!< contract tx
	REG_CONT_TX                        //!< register contract
	DELEGATE_TX                        //!< delegate tx

	FCOIN_STAKE_TX           = 8
	ASSET_ISSUE_TX           = 9  //!< a user issues onchain asset
	ASSET_UPDATE_TX          = 10 //!< a user update onchain asset
	UCOIN_TRANSFER_TX        = 11
	UCONTRACT_DEPLOY_TX      = 14 //!< universal VM contract deployment
	UCOIN_CONTRACT_INVOKE_TX = 15
	PRICE_FEED_TX            = 16

	CDP_STAKE_TX     = 21
	CDP_REDEEMP_TX   = 22
	CDP_LIQUIDATE_TX = 23

	DEX_SETTLE_TX            = 89 //!< dex settle Tx
	DEX_CANCEL_ORDER_TX      = 88 //!< dex cancel order Tx
	DEX_BUY_LIMIT_ORDER_TX   = 84 //!< dex buy limit price order Tx
	DEX_SELL_LIMIT_ORDER_TX  = 85 //!< dex sell limit price order Tx
	DEX_BUY_MARKET_ORDER_TX  = 86 //!< dex buy market price order Tx
	DEX_SELL_MARKET_ORDER_TX = 87 //!< dex sell market price order Tx
)
View Source
const (
	UINT16_MAX = ^uint16(0)
	UINT32_MAX = ^uint32(0)
	UINT_MAX   = ^uint(0)
	UINT64_MAX = ^uint64(0)
)
View Source
const (
	// MainNet represents the main wicc network.
	MainNet wire.BitcoinNet = 0xff421d1a

	// TestNet represents the  test wicc network.
	TestNet wire.BitcoinNet = 0xfd7d5cd7

	// Default entropy size for mnemonic
	DefaultEntropySize = 128
	// Default seed pass. it used to generate seed from mnemonic( BIP39 ). Don't change if determined
	DefaultSeedPass = ""

	HardenedKeyZeroIndex        = 0x8001869f
	BIP44Purpose         uint32 = 0x8000002C
	WICCCoinType         uint32 = 99999

	MAINNET Network = 1
	TESTNET Network = 2

	BIP44PATH = "m/44'/99999'/0'/0/0"
)
View Source
const (
	ENGLISH  MnemonicLanguage = "EN"
	JAPANESE                  = "JP"
	FRENCH                    = "FR"
	ITALIAN                   = "IT"
	KOREAN                    = "KR"
	SPANISH                   = "ES"
)

List Mnemonic language support

View Source
const (
	WICC CoinType = "WICC"
	WGRT          = "WGRT"
	WUSD          = "WUSD"
	WCNY          = "WCNY"
	WBTC          = "WBTC"
	WETH          = "WETH"
	WEOS          = "WEOS"
	USD           = "USD"
	CNY           = "CNY"
	EUR           = "EUR"
	BTC           = "BTC"
	USDT          = "USDT"
	GOLD          = "GOLD"
	KWH           = "KWH"
)
View Source
const (
	ASSET_OWNER_UID   AssetUpdateType = 1
	ASSET_NAME                        = 2
	ASSET_MINT_AMOUNT                 = 3
)
View Source
const (
	//HardenedKeyStart hardended key starts.
	HardenedKeyStart uint32 = 0x80000000 // 2^31

)

Variables

View Source
var (
	// ErrInvalidSeedLen seed Len error
	ErrInvalidSeedLen = errors.New("seed lenght must be between 128 and 512 bits")
	// ErrUnusableSeed describes an error in which the provided seed is not
	// usable due to the derived key falling outside of the valid range for
	// secp256k1 private keys.  This error indicates the caller must choose
	// another seed.
	ErrUnusableSeed = errors.New("unusable seed")

	// ErrKeyByteSize error extended key bytes
	ErrKeyByteSize = errors.New("error extended key bytes")

	//ErrDeriveBeyondMaxDepth max 255 indices
	ErrDeriveBeyondMaxDepth = errors.New("cannot derive a key with more than 255 indices in its path")

	// ErrDeriveHardFromPublic cannot derive a hardened key from a public key
	ErrDeriveHardFromPublic = errors.New("cannot derive a hardened key from a public key")

	//ErrInvalidChild  child index invalid
	ErrInvalidChild = errors.New("the extended key at this index is invalid")

	// ErrNotPrivExtKey  not Private Key
	ErrNotPrivExtKey = errors.New("cant't create private keys from public extended key")
)
View Source
var (
	// ErrInvalidMnemonic is returned when trying to use a malformed mnemonic.
	ErrInvalidMnemonic = errors.New("Invalid mnenomic")

	// ErrEntropyLengthInvalid is returned when trying to use an entropy set with
	// an invalid size.
	ErrEntropyLengthInvalid = errors.New("Entropy length must be [128, 256] and a multiple of 32")

	// ErrValidatedSeedLengthMismatch is returned when a validated seed is not the
	// same size as the given seed. This should never happen is present only as a
	// sanity assertion.
	ErrValidatedSeedLengthMismatch = errors.New("Seed length does not match validated seed length")

	// ErrChecksumIncorrect is returned when entropy has the incorrect checksum.
	ErrChecksumIncorrect = errors.New("Checksum incorrect")
)
View Source
var ErrKeyPathFormat = errors.New("Wallet Path Error")
View Source
var ErrParentKey = errors.New("Key must master")
View Source
var WaykiMainNetParams = chaincfg.Params{
	PubKeyHashAddrID: 0x49,
	PrivateKeyID:     0x99,
	HDPrivateKeyID:   [4]byte{0x04, 0x88, 0xad, 0xe4},
	HDPublicKeyID:    [4]byte{0x04, 0x88, 0xb2, 0x1e},
	HDCoinType:       99999,
}
View Source
var WaykiTestNetParams = chaincfg.Params{
	PubKeyHashAddrID: 0x87,
	PrivateKeyID:     0xd2,
	HDPrivateKeyID:   [4]byte{0x04, 0x88, 0xad, 0xe4},
	HDPublicKeyID:    [4]byte{0x04, 0x88, 0xb2, 0x1e},
	HDCoinType:       99999,
}

Functions

func EntropyFromMnemonic

func EntropyFromMnemonic(mnemonic string) ([]byte, error)

EntropyFromMnemonic takes a mnemonic generated by this library, and returns the input entropy used to generate the given mnemonic. An error is returned if the given mnemonic is invalid.

func GetAddressFromMnemonic

func GetAddressFromMnemonic(words string, net Network) string

func GetAddressFromPrivateKey

func GetAddressFromPrivateKey(priv string, net Network) string

func GetPrivateKeyFromMnemonic

func GetPrivateKeyFromMnemonic(words string, net Network) string

func GetWordList

func GetWordList() []string

GetWordList gets the list of words to use for mnemonics.

func IsMnemonicValid

func IsMnemonicValid(mnemonic string) bool

IsMnemonicValid attempts to verify that the provided mnemonic is valid. Validity is determined by both the number of words being appropriate, and that all the words in the mnemonic are present in the word list.

func IsRegIdStr

func IsRegIdStr(regId string) bool

func MnemonicToByteArray

func MnemonicToByteArray(mnemonic string, raw ...bool) ([]byte, error)

MnemonicToByteArray takes a mnemonic string and turns it into a byte array suitable for creating another mnemonic. An error is returned if the mnemonic is invalid.

func NetworkToChainConfig

func NetworkToChainConfig(net Network) (*chaincfg.Params, error)

func NewEntropy

func NewEntropy(bitSize int) ([]byte, error)

NewEntropy will create random entropy bytes so long as the requested size bitSize is an appropriate size.

bitSize has to be a multiple 32 and be within the inclusive range of {128, 256}

func NewMnemonic

func NewMnemonic(entropy []byte) (string, error)

NewMnemonic will return a string consisting of the mnemonic words for the given entropy. If the provide entropy is invalid, an error will be returned.

func NewSeed

func NewSeed(mnemonic string, password string) []byte

NewSeed creates a hashed seed output given a provided string and password. No checking is performed to validate that the string provided is a valid mnemonic.

func NewSeedWithErrorChecking

func NewSeedWithErrorChecking(mnemonic string, password string) ([]byte, error)

NewSeedWithErrorChecking creates a hashed seed output given the mnemonic string and a password. An error is returned if the mnemonic is not convertible to a byte array.

func SetWordList

func SetWordList(list []string)

SetWordList sets the list of words to use for mnemonics. Currently the list that is set is used package-wide.

func WriteContractScript

func WriteContractScript(writer *WriterHelper, script []byte, description string)

Types

type AddressId

type AddressId []byte

type AssetModel

type AssetModel struct {
	AssetAmount int64  //
	AssetSymbol string //
}

type AssetUpdateType

type AssetUpdateType int

type ChangeType

type ChangeType uint32

type CoinType

type CoinType string

type Dest

type Dest struct {
	CoinSymbol string //From Coin Type
	CoinAmount uint64
	DestAddr   *UserIdWraper
}

type ExtendedKey

type ExtendedKey struct {
	DerivationPath string
	// contains filtered or unexported fields
}

ExtendedKey private/public key data

func NewMasterKey

func NewMasterKey(seed []byte, params *chaincfg.Params) (*ExtendedKey, error)

NewMasterKey create a new master key data from seed

func (*ExtendedKey) Address

func (key *ExtendedKey) Address() (*ec.AddressPubKeyHash, error)

Address return pay-to-pubkey-has (P2PKH) address

func (*ExtendedKey) B58Serialize

func (key *ExtendedKey) B58Serialize() string

func (*ExtendedKey) DerivePath

func (key *ExtendedKey) DerivePath(pathStr string) (*ExtendedKey, error)

DerivePath return key by path : m/0'/1/2' etc...

func (*ExtendedKey) ECPrivKey

func (key *ExtendedKey) ECPrivKey() (*ec.PrivateKey, error)

func (*ExtendedKey) HardenedChild

func (key *ExtendedKey) HardenedChild(i uint32) (*ExtendedKey, error)

HardenedChild derivation hardened child

func (*ExtendedKey) Serialize

func (key *ExtendedKey) Serialize() ([]byte, error)

type MnemonicLanguage

type MnemonicLanguage string

type Network

type Network int16

type OperVoteFund

type OperVoteFund struct {
	VoteType  WaykiVoteType
	PubKey    *PubKeyId
	VoteValue int64
}

type PubKeyId

type PubKeyId []byte

func NewPubKeyIdByKey

func NewPubKeyIdByKey(privKey *btcec.PrivateKey) *PubKeyId

func NewPubKeyIdByStr

func NewPubKeyIdByStr(str string) *PubKeyId

type RegId

type RegId struct {
	Height uint64
	Index  uint64
}

func ParseRegId

func ParseRegId(regId string) *RegId

type UserIdType

type UserIdType int
const (
	UID_REG     UserIdType = iota //< reg id
	UID_PUB_KEY                   //< public key
	UID_ADDRESS                   //< wicc address
)

type UserIdWraper

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

func NewAdressUid

func NewAdressUid(address AddressId) *UserIdWraper

func NewAdressUidByStr

func NewAdressUidByStr(address string) *UserIdWraper

func NewPubKeyUid

func NewPubKeyUid(pubKey PubKeyId) *UserIdWraper

func NewPubKeyUidByStr

func NewPubKeyUidByStr(pubKey string) *UserIdWraper

func NewRegUid

func NewRegUid(regId RegId) *UserIdWraper

func NewRegUidByStr

func NewRegUidByStr(regId string) *UserIdWraper

func (UserIdWraper) GetId

func (uid UserIdWraper) GetId() interface{}

func (UserIdWraper) GetType

func (uid UserIdWraper) GetType() UserIdType

type WICCNet

type WICCNet uint32

type WalletAddress

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

type WalletStatus

type WalletStatus int64

type WaykiAssetIssueTx

type WaykiAssetIssueTx struct {
	WaykiBaseSignTx
	Fees        uint64
	FeeSymbol   string //Fee Type (WICC/WUSD)
	AssetSymbol string //From Coin Type
	AssetName   string
	AssetTotal  uint64
	AssetOwner  *UserIdWraper
	MinTable    bool
}

func (WaykiAssetIssueTx) SignTx

func (tx WaykiAssetIssueTx) SignTx(wifKey *btcutil.WIF) string

type WaykiAssetUpdateTx

type WaykiAssetUpdateTx struct {
	WaykiBaseSignTx
	Fees        uint64
	UpdateType  int
	FeeSymbol   string //Fee Type (WICC/WUSD)
	AssetSymbol string //From Coin Type
	AssetName   string
	AssetTotal  uint64
	AssetOwner  *UserIdWraper
}

func (WaykiAssetUpdateTx) SignTx

func (tx WaykiAssetUpdateTx) SignTx(wifKey *btcutil.WIF) string

type WaykiBaseSignTx

type WaykiBaseSignTx struct {
	TxType      WaykiTxType
	Version     int64
	ValidHeight int64
	PubKey      []byte
	UserId      *UserIdWraper // current operating user id, the one want to do something
}

type WaykiCallContractTx

type WaykiCallContractTx struct {
	WaykiBaseSignTx
	AppId    *UserIdWraper //user regid or user key id or app regid
	Fees     uint64
	Values   uint64 //transfer amount
	Contract []byte
}

func (WaykiCallContractTx) SignTx

func (tx WaykiCallContractTx) SignTx(wifKey *btcutil.WIF) string

type WaykiCdpLiquidateTx

type WaykiCdpLiquidateTx struct {
	WaykiBaseSignTx
	Fees            uint64
	ScoinsLiquidate uint64 //Scoin  Liquidate
	FeeSymbol       string //Fee Type (WICC/WUSD)
	CdpTxHash       []byte
	AseetSymbol     string
}

func (WaykiCdpLiquidateTx) SignTx

func (tx WaykiCdpLiquidateTx) SignTx(wifKey *btcutil.WIF) string

type WaykiCdpRedeemTx

type WaykiCdpRedeemTx struct {
	WaykiBaseSignTx
	Fees        uint64
	ScoinValues uint64 //Stake Coin
	Assets      []AssetModel
	FeeSymbol   string //Fee Type (WICC/WUSD)
	CdpTxHash   []byte
}

func (WaykiCdpRedeemTx) SignTx

func (tx WaykiCdpRedeemTx) SignTx(wifKey *btcutil.WIF) string

type WaykiCdpStakeTx

type WaykiCdpStakeTx struct {
	WaykiBaseSignTx
	Fees        uint64
	ScoinValues uint64 //get Coin amount
	FeeSymbol   string //Fee Type (WICC/WUSD)
	ScoinSymbol string //get Coin Type
	Assets      []AssetModel
	CdpTxHash   []byte
}

func (WaykiCdpStakeTx) SignTx

func (tx WaykiCdpStakeTx) SignTx(wifKey *btcutil.WIF) string

type WaykiCommonTx

type WaykiCommonTx struct {
	WaykiBaseSignTx
	Fees   uint64
	Values uint64
	Memo   string
	DestId *UserIdWraper //< the dest id(reg id or address or public key) received the wicc values
}

func (WaykiCommonTx) SignTx

func (tx WaykiCommonTx) SignTx(wifKey *btcutil.WIF) string

type WaykiDelegateTx

type WaykiDelegateTx struct {
	WaykiBaseSignTx
	OperVoteFunds []OperVoteFund
	Fees          uint64
}

func (WaykiDelegateTx) SignTx

func (tx WaykiDelegateTx) SignTx(wifKey *btcutil.WIF) string

type WaykiDexCancelTx

type WaykiDexCancelTx struct {
	WaykiBaseSignTx
	Fees      uint64
	FeeSymbol string //Fee Type (WICC/WUSD)
	DexHash   []byte //From Coin Type
}

func (WaykiDexCancelTx) SignTx

func (tx WaykiDexCancelTx) SignTx(wifKey *btcutil.WIF) string

type WaykiDexMarketTx

type WaykiDexMarketTx struct {
	WaykiBaseSignTx
	Fees        uint64
	FeeSymbol   string //Fee Type (WICC/WUSD)
	CoinSymbol  string //From Coin Type
	AssetSymbol string
	AssetAmount uint64
	DestId      *UserIdWraper //< the dest id(reg id or address or public key) received the wicc values
}

func (WaykiDexMarketTx) SignTx

func (tx WaykiDexMarketTx) SignTx(wifKey *btcutil.WIF) string

type WaykiDexSellLimitTx

type WaykiDexSellLimitTx struct {
	WaykiBaseSignTx
	Fees        uint64
	FeeSymbol   string //Fee Type (WICC/WUSD)
	CoinSymbol  string //From Coin Type
	AssetSymbol string
	AssetAmount uint64
	AskPrice    uint64
	DestId      *UserIdWraper //< the dest id(reg id or address or public key) received the wicc values
}

func (WaykiDexSellLimitTx) SignTx

func (tx WaykiDexSellLimitTx) SignTx(wifKey *btcutil.WIF) string

type WaykiRegisterAccountTx

type WaykiRegisterAccountTx struct {
	WaykiBaseSignTx
	MinerId *UserIdWraper
	Fees    uint64
}

func (WaykiRegisterAccountTx) SignTx

func (tx WaykiRegisterAccountTx) SignTx(wifKey *btcutil.WIF) string

type WaykiRegisterContractTx

type WaykiRegisterContractTx struct {
	WaykiBaseSignTx
	Script      []byte
	Description string
	Fees        uint64
}

func (WaykiRegisterContractTx) SignTx

func (tx WaykiRegisterContractTx) SignTx(wifKey *btcutil.WIF) string

sign transaction

type WaykiRewardTx

type WaykiRewardTx struct {
	WaykiBaseSignTx
	Values uint64 // reward values
}

func (WaykiRewardTx) SignTx

func (tx WaykiRewardTx) SignTx(wifKey *btcutil.WIF) string

type WaykiTxType

type WaykiTxType uint32

type WaykiUCoinCallContractTx

type WaykiUCoinCallContractTx struct {
	WaykiBaseSignTx
	AppId      *UserIdWraper //user regid or user key id or app regid
	Fees       int64
	CoinAmount int64  //transfer amount
	FeeSymbol  string //Fee Type (WICC/WUSD)
	CoinSymbol string //From Coin Type
	Contract   []byte
}

func (WaykiUCoinCallContractTx) SignTx

func (tx WaykiUCoinCallContractTx) SignTx(wifKey *btcutil.WIF) string

type WaykiUCoinRegisterContractTx

type WaykiUCoinRegisterContractTx struct {
	WaykiBaseSignTx
	Script      []byte
	Description string
	Fees        uint64
	FeeSymbol   string
}

func (WaykiUCoinRegisterContractTx) SignTx

func (tx WaykiUCoinRegisterContractTx) SignTx(wifKey *btcutil.WIF) string

sign transaction

type WaykiUCoinTransferTx

type WaykiUCoinTransferTx struct {
	WaykiBaseSignTx
	Fees      uint64
	FeeSymbol string //Fee Type (WICC/WUSD)
	Dests     []Dest
	Memo      string
}

func (WaykiUCoinTransferTx) SignTx

func (tx WaykiUCoinTransferTx) SignTx(wifKey *btcutil.WIF) string

type WaykiVoteType

type WaykiVoteType uint32
const (
	NULL_OPER  WaykiVoteType = iota
	ADD_FUND                 //投票
	MINUS_FUND               //撤销投票
)

func GetVoteTypeByValue

func GetVoteTypeByValue(value int64) WaykiVoteType

type WriterHelper

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

func NewWriterHelper

func NewWriterHelper(buf *bytes.Buffer) *WriterHelper

func (WriterHelper) GetBuf

func (writer WriterHelper) GetBuf() *bytes.Buffer

func (WriterHelper) Write

func (writer WriterHelper) Write(p []byte)

func (WriterHelper) WriteAddressId

func (writer WriterHelper) WriteAddressId(value AddressId)

func (WriterHelper) WriteByte

func (writer WriterHelper) WriteByte(value byte)

func (WriterHelper) WriteBytes

func (writer WriterHelper) WriteBytes(value []byte)

func (WriterHelper) WriteCdpAsset

func (write WriterHelper) WriteCdpAsset(assets []AssetModel)

func (WriterHelper) WriteCompactSize

func (writer WriterHelper) WriteCompactSize(value uint64)

func (WriterHelper) WriteContractScript

func (writer WriterHelper) WriteContractScript(script []byte, description string)

func (WriterHelper) WriteIntData

func (writer WriterHelper) WriteIntData(data interface{})

func (WriterHelper) WritePubKeyId

func (writer WriterHelper) WritePubKeyId(value PubKeyId)

func (WriterHelper) WriteRegId

func (writer WriterHelper) WriteRegId(value RegId)

func (WriterHelper) WriteReverse

func (writer WriterHelper) WriteReverse(value []byte)

func (WriterHelper) WriteString

func (writer WriterHelper) WriteString(value string)

func (WriterHelper) WriteUserId

func (writer WriterHelper) WriteUserId(value *UserIdWraper)

func (WriterHelper) WriteVarInt

func (writer WriterHelper) WriteVarInt(value int64)

Directories

Path Synopsis
Package base58 provides ...
Package base58 provides ...
Package bytes provides ...
Package bytes provides ...
Package address provides ...
Package address provides ...
Package utils provides ...
Package utils provides ...
Package wif provides ...
Package wif provides ...

Jump to

Keyboard shortcuts

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