utility

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommKeyIdentifierUndefined = 0
	CommKeyIdentifierRSAOAEP   = 1
)

)

View Source
const (
	ModuleIdentifierECDSATxOut               = 1
	ModuleIdentifierECDSATxIn                = 2
	ModuleIdentifierECDSANameRegistration    = 3
	ModuleIdentifierECDSANameUnregistration  = 4
	ModuleIdentifierECDSARegistredNameCommit = 5
)

)

View Source
const ChunkFileMaxSize = 20 * 1024 * 1024 //100*1024*1024
View Source
const ExtrabytesMaxSize = 100
View Source
const HashSize = 32
View Source
const RegistredNameMaxSize = 10

Variables

This section is empty.

Functions

func BigIntFromCompact

func BigIntFromCompact(compact uint32) *big.Int

func BigIntFromHash

func BigIntFromHash(h *Hash) *big.Int

func CorrectTargetBigInt(targetbigint *big.Int,timestamp int64,prevtimestamp int64) *big.Int{

	obstructioncoeff:=(timestamp-prevtimestamp)/(60*600)//OBSTRUCTED_MINING_TIME// about ten hours
	if obstructioncoeff==0 {
		//obstructioncoeff=1
		return targetbigint
	}

	obstructioncoeffbigint:=big.NewInt(obstructioncoeff)
	targetbigint.Mul(targetbigint,obstructioncoeffbigint)

	return targetbigint
}

func CompactFromBigInt

func CompactFromBigInt(value *big.Int) uint32

func ComputeHashBytes

func ComputeHashBytes(b []byte) []byte

func DecodeBytecodeId

func DecodeBytecodeId(bytecode []byte) uint32

func DecodeECDSANameUnregistration

func DecodeECDSANameUnregistration(bytecode []byte) ([]byte, []byte, error)
func DecodeECDSANamePublicPost(bytecode []byte) ([]byte,*Extradata,error){
	tmpbr:=NewBufferReader(bytecode)
	primitivemoduleid:=tmpbr.GetUint32()
	if primitivemoduleid != ModuleIdentifierECDSANamePublicPost{
		return nil,nil,fmt.Errorf("Not an ECDSA Name Unregistration")
	}
	pubkeycompressedlen:=tmpbr.GetVarUint()
	pubkeycompressed:=tmpbr.GetBytes(uint(pubkeycompressedlen))

	ed:=tmpbr.GetExtradata()
	tmpbrerr:=tmpbr.GetError()
	if tmpbrerr!=nil{
		return nil,nil,tmpbrerr
	}
	if !tmpbr.EndOfBytes(){
		return nil,nil,fmt.Errorf("End of bytes not reached")
	}

	return pubkeycompressed,ed,nil
}

func DecodeECDSATxInBytecode

func DecodeECDSATxInBytecode(bytecode []byte) ([]byte, []byte, error)

func Decrypt

func Decrypt(key, text []byte) ([]byte, error)

func Encrypt

func Encrypt(key, text []byte) ([]byte, error)

func GetUserSecretEntry added in v0.2.4

func GetUserSecretEntry() (string, error)
func main() {
	fmt.Print("Enter Password: ")
	password, _ := GetUserSecretEntry()
	fmt.Printf(" Password: %s\n", password)
}

go get golang.org/x/term

func LoadBytesFile

func LoadBytesFile(path string) (*[]byte, error)

func PrintBytes

func PrintBytes(b []byte)

func PrivKeyFromBytes

func PrivKeyFromBytes(pkbytes []byte) btcec.PrivateKey

func SaveBytesFile

func SaveBytesFile(bytesfilebytes []byte, bytesfilepath string) error

func Sign

func Sign(pk *btcec.PrivateKey, msgbytes []byte) []byte
func NewPrivateKey() (btcec.PrivateKey,error) {
	pk,err:=btcec.NewPrivateKey()
	return *pk,err
}

func VerifySignature

func VerifySignature(signinghash Hash, signaturebytes []byte, pubkeycompressedbytes []byte) error

Types

type BufferReader

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

func NewBufferReader

func NewBufferReader(content []byte) *BufferReader

func (*BufferReader) EndOfBytes

func (br *BufferReader) EndOfBytes() bool

func (*BufferReader) GetBigInt

func (br *BufferReader) GetBigInt() *big.Int

func (*BufferReader) GetBytes

func (br *BufferReader) GetBytes(length uint) []byte

func (*BufferReader) GetCounter

func (br *BufferReader) GetCounter() uint

func (*BufferReader) GetError

func (br *BufferReader) GetError() error

func (*BufferReader) GetExtrabytes

func (br *BufferReader) GetExtrabytes() []byte

func (*BufferReader) GetHash

func (br *BufferReader) GetHash() Hash

func (*BufferReader) GetUint16

func (br *BufferReader) GetUint16() uint16

func (*BufferReader) GetUint32

func (br *BufferReader) GetUint32() uint32

func (*BufferReader) GetUint64

func (br *BufferReader) GetUint64() uint64

func (*BufferReader) GetUint8

func (br *BufferReader) GetUint8() uint8

func (*BufferReader) GetVarUint

func (br *BufferReader) GetVarUint() uint64

type BufferWriter

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

func NewBufferWriter

func NewBufferWriter() *BufferWriter

func (*BufferWriter) GetContent

func (bw *BufferWriter) GetContent() []byte

func (*BufferWriter) PutBigInt

func (bw *BufferWriter) PutBigInt(i *big.Int)

func (*BufferWriter) PutBytes

func (bw *BufferWriter) PutBytes(buf []byte)

func (*BufferWriter) PutHash

func (bw *BufferWriter) PutHash(h Hash)

func (*BufferWriter) PutRegistredNameKey

func (bw *BufferWriter) PutRegistredNameKey(name []byte)

func (*BufferWriter) PutUint16

func (bw *BufferWriter) PutUint16(i uint16)

func (*BufferWriter) PutUint32

func (bw *BufferWriter) PutUint32(i uint32)

func (*BufferWriter) PutUint64

func (bw *BufferWriter) PutUint64(i uint64)

func (*BufferWriter) PutUint8

func (bw *BufferWriter) PutUint8(i uint8)

func (*BufferWriter) PutVarUint

func (bw *BufferWriter) PutVarUint(i uint64)

type ChunkStorage

type ChunkStorage struct {
	Path string

	//
	Chunkposition []int64
	Chunksize     []int64
	Chunkfileid   []int
	// contains filtered or unexported fields
}

ChunkStorage is

func OpenChunkStorage

func OpenChunkStorage(storagepath string) *ChunkStorage

OpenChunkStorage is

func (*ChunkStorage) AddChunk

func (cs *ChunkStorage) AddChunk(data []byte) error

func (*ChunkStorage) GetChunk

func (cs *ChunkStorage) GetChunk(position int64, length int64, fileid int) []byte

func (*ChunkStorage) GetChunkById

func (cs *ChunkStorage) GetChunkById(chunkid int) []byte

func (*ChunkStorage) NbChunks

func (cs *ChunkStorage) NbChunks() int

type Hash

type Hash [HashSize]byte

func ComputeHash

func ComputeHash(b []byte) Hash

func ComputeHashTreeBranche

func ComputeHashTreeBranche(left *Hash, right *Hash) *Hash

func ComputeRoot

func ComputeRoot(hashes *[]Hash) Hash

func DecodeECDSANameRegistration

func DecodeECDSANameRegistration(bytecode []byte) (*Hash, []byte, []byte, []byte, error)

func DecodeECDSATxOutBytecode

func DecodeECDSATxOutBytecode(bytecode []byte) (*Hash, []byte, error)

func NewHash

func NewHash(bytes []byte) *Hash

type Transaction

type Transaction struct {
	Version int32
	//TODO locktime
	//Timestamp int64
	Vin  []TxIn
	Vout []TxOut
}

func NewRewardTransaction

func NewRewardTransaction(Value uint64, Fee uint64, Pubkeyhash Hash) *Transaction

func UnserializeTransaction

func UnserializeTransaction(bytes []byte) (*Transaction, error)

func (*Transaction) ComputeHash

func (tx *Transaction) ComputeHash() Hash

func (*Transaction) ComputeSigningHash

func (tx *Transaction) ComputeSigningHash() (Hash, error)

func (*Transaction) JSONSerialize

func (tx *Transaction) JSONSerialize() []byte

func (*Transaction) Serialize

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

type TxIn

type TxIn struct {
	Hash      Hash
	Index     uint32
	Bytecode  []byte
	Signature []byte
}

func NewECDSANameUnregistration

func NewECDSANameUnregistration(inhash Hash, index uint32, pubkeycompressedbytes []byte) TxIn

func NewECDSARegistredNameCommit added in v0.2.4

func NewECDSARegistredNameCommit(inhash Hash, index uint32, pubkeycompressedbytes []byte, commitbytes []byte) TxIn

func NewECDSATxIn

func NewECDSATxIn(inhash Hash, index uint32, pubkeycompressedbytes []byte) TxIn

type TxOut

type TxOut struct {
	Value uint64 // in milion globals
	//Address Hash
	Bytecode []byte
}

func NewECDSANameRegistration

func NewECDSANameRegistration(Value uint64, Name []byte, Pubkeyhash Hash, CommKeyIdentifier uint32, CommPubkey []byte) TxOut

func NewECDSATxOut

func NewECDSATxOut(Value uint64, Pubkeyhash Hash) TxOut

func (*TxOut) CompareWithAddress

func (txout *TxOut) CompareWithAddress(addr Hash) bool
func NewECDSAEngagementRewardClaim(engagementtxhash Hash,engagementtxindex uint32,pubkeycompressedbytes []byte) TxIn{
	var tmptxin TxIn
	tmptxin.Hash=engagementtxhash
	tmptxin.Index=engagementtxindex
	tmpbw:=NewBufferWriter()
	tmpbw.PutUint32(ModuleIdentifierECDSAEngagementPublicPostRewardClaim)//
	tmpbw.PutVarUint(uint64(len(pubkeycompressedbytes)))
	tmpbw.PutBytes(pubkeycompressedbytes)
	tmpbw.PutVarUint(uint64 (0)) //no extradata
	tmptxin.Bytecode=append(tmptxin.Bytecode,tmpbw.GetContent()...)
	return tmptxin
}
func NewECDSAEngagementPublicPost(eid uint32,stakedamount uint64,txhash Hash,index uint32,claimaddress Hash) TxOut{
	var tmptxout TxOut
	tmptxout.Value=stakedamount
	tmpbw:=NewBufferWriter()
	tmpbw.PutUint32(ModuleIdentifierECDSAEngagementPublicPost)//
	tmpbw.PutUint32(eid)//EngagementIdentifierLikePublicPost or EngagementIdentifierDislikePublicPost
	//tmpbw.PutVarUint(uint64(len(name)))
	tmpbw.PutHash(txhash)
	tmpbw.PutUint32(index)
	tmpbw.PutHash(claimaddress)
	tmpbw.PutVarUint(0)// No extradata
	tmptxout.Bytecode=tmpbw.GetContent()
	return tmptxout
}

func (*TxOut) GetAssetState

func (txout *TxOut) GetAssetState() string

Jump to

Keyboard shortcuts

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