utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ARToWinston

func ARToWinston(a *big.Float) *big.Int

ARToWinston 1 AR = 1000000000000

func Base64Decode

func Base64Decode(data string) ([]byte, error)

func Base64Encode

func Base64Encode(data []byte) string

func BundleItemSignData

func BundleItemSignData(d schema.BundleItem) ([]byte, error)

func ByteArrayToLong

func ByteArrayToLong(b []byte) int

func ConcatBuffer

func ConcatBuffer(buffers ...[]byte) []byte

ConcatBuffer 更好的 slice append

func ContainsInSlice

func ContainsInSlice(items []string, item string) bool

ContainsInSlice checks if a string is in a slice of strings

func DecodeBlock

func DecodeBlock(body string) (*schema.Block, error)

func DecodeBundle

func DecodeBundle(bundleBinary []byte) (schema.Bundle, error)

func DecodeBundleItem

func DecodeBundleItem(itemBinary []byte) (schema.BundleItem, error)

func DecodeBundleItemStream

func DecodeBundleItemStream(itemBinary io.Reader) (schema.BundleItem, error)

func DecodeBundleStream

func DecodeBundleStream(bundleData *os.File) (schema.Bundle, error)

func DeepHash

func DeepHash(data []interface{}) [48]byte

func DeserializeTags

func DeserializeTags(data []byte) ([]schema.Tag, error)

func GenerateChunks

func GenerateChunks(data interface{}) (schema.Chunks, error)

*

  • Generates the data_root, chunks & proofs
  • needed for a transaction. *
  • This also checks if the last chunk is a zero-length
  • chunk and discards that chunk and proof if so.
  • (we do not need to upload this zero length chunk) *
  • @param data

func GenerateIndepHash

func GenerateIndepHash(b schema.Block) string

func GenerateItemBinary

func GenerateItemBinary(d schema.BundleItem) (by []byte, err error)

func GenerateItemBinaryStream

func GenerateItemBinaryStream(d schema.BundleItem) (binaryReader io.Reader, err error)

func GenerateRsaKey

func GenerateRsaKey(bits int) (*rsa.PrivateKey, error)

func GetBundleItemTagsBytes

func GetBundleItemTagsBytes(itemBinary []byte) ([]byte, error)

func GetChunk

func GetChunk(tx schema.Transaction, idx int, data []byte) (*schema.GetChunk, error)

func GetChunkStream

func GetChunkStream(tx schema.Transaction, idx int, data *os.File) (*schema.GetChunk, error)

func GetSignatureData

func GetSignatureData(tx *schema.Transaction) ([]byte, error)

func Hash

func Hash(data [][]byte) []byte

func ItemSignerAddr

func ItemSignerAddr(b schema.BundleItem) (string, error)

func LongTo32ByteArray

func LongTo32ByteArray(long int) []byte

func LongTo8ByteArray

func LongTo8ByteArray(long int) []byte

func NewBundle

func NewBundle(items ...schema.BundleItem) (schema.Bundle, error)

func NewBundleItem

func NewBundleItem(owner string, signatureType int, target, anchor string, data []byte, tags []schema.Tag) (schema.BundleItem, error)

func NewBundleItemStream

func NewBundleItemStream(owner string, signatureType int, target, anchor string, data io.Reader, tags []schema.Tag) (schema.BundleItem, error)

func NewBundleStream

func NewBundleStream(items ...schema.BundleItem) (schema.Bundle, error)

func OwnerToAddress

func OwnerToAddress(owner string) (string, error)

func OwnerToPubKey

func OwnerToPubKey(owner string) (*rsa.PublicKey, error)

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

func PrepareChunks

func PrepareChunks(tx *schema.Transaction, data interface{}, dataSize int) error

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

func SerializeTags

func SerializeTags(tags []schema.Tag) ([]byte, error)

func ShortTo2ByteArray

func ShortTo2ByteArray(long int) []byte

func Sign

func Sign(msg []byte, prvKey *rsa.PrivateKey) ([]byte, error)

func SignTransaction

func SignTransaction(tx *schema.Transaction, prvKey *rsa.PrivateKey) error

func TagsDecode

func TagsDecode(base64Tags []schema.Tag) ([]schema.Tag, error)

func TagsEncode

func TagsEncode(tags []schema.Tag) []schema.Tag

func Verify

func Verify(msg []byte, pubKey *rsa.PublicKey, sign []byte) error

func VerifyBundleItem

func VerifyBundleItem(d schema.BundleItem) error

func VerifyTransaction

func VerifyTransaction(tx schema.Transaction) (err error)

func WinstonToAR

func WinstonToAR(w *big.Int) *big.Float

WinstonToAR 1 Winston = 0.000000000001 AR

Types

type ValidateResult

type ValidateResult struct {
	Offset     int
	LeftBound  int
	RightBound int
	ChunkSize  int
}

func ValidatePath

func ValidatePath(id []byte, dest, leftBound, rightBound int, path []byte) (*ValidateResult, bool)

验证 merkle path

Jump to

Keyboard shortcuts

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