filecoin

package
v0.14.14 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxLenUvarint63 is the maximum number of bytes representing an uvarint in
	// this encoding, supporting a maximum value of 2^63 (uint63), aka
	// MaxValueUvarint63.
	MaxLenUvarint63 = 9

	// MaxValueUvarint63 is the maximum encodable uint63 value.
	MaxValueUvarint63 = (1 << 63) - 1
)
View Source
const BlsPrivateKeyBytes = 32

BlsPrivateKeyBytes is the length of a BLS private key

View Source
const BlsPublicKeyBytes = 48

BlsPublicKeyBytes is the length of a BLS public key

View Source
const ChecksumHashLength = 4

ChecksumHashLength defines the hash length used for calculating address checksums.

View Source
const MainnetPrefix = "f"

MainnetPrefix is the main network prefix.

View Source
const MaxAddressStringLength = 2 + 84

MaxAddressStringLength is the max length of an address encoded as a string it include the network prefx, protocol, and bls publickey

View Source
const PayloadHashLength = 20

PayloadHashLength defines the hash length taken over addresses using the Actor and SECP256K1 protocols.

Variables

View Source
var (
	// ErrUnknownNetwork is returned when encountering an unknown network in an address.
	ErrUnknownNetwork = errors.New("unknown address network")

	// ErrUnknownProtocol is returned when encountering an unknown protocol in an address.
	ErrUnknownProtocol = errors.New("unknown address protocol")
	// ErrInvalidPayload is returned when encountering an invalid address payload.
	ErrInvalidPayload = errors.New("invalid address payload")
	// ErrInvalidLength is returned when encountering an address of invalid length.
	ErrInvalidLength = errors.New("invalid address length")
	// ErrInvalidChecksum is returned when encountering an invalid address checksum.
	ErrInvalidChecksum = errors.New("invalid address checksum")
)
View Source
var (
	FilecoinChainBase string
	FilecoinChainId   crypto.Hash
)
View Source
var (
	ErrOverflow   = errors.New("varints larger than uint63 not supported")
	ErrUnderflow  = errors.New("varints malformed, could not reach the end")
	ErrNotMinimal = errors.New("varint not minimally encoded")
)
View Source
var AddressEncoding = base32.NewEncoding(encodeStd)

AddressEncoding defines the base32 config used for address encoding and decoding.

View Source
var CurrentNetwork = Mainnet

CurrentNetwork specifies which network the address belongs to

View Source
var Undef = Address{}

Undef is the type that represents an undefined address.

View Source
var UndefAddressString = "<empty>"

UndefAddressString is the string used to represent an empty address when encoded to a string.

Functions

func Checksum added in v0.13.6

func Checksum(ingest []byte) []byte

Checksum returns the checksum of `ingest`.

func FromUvarint added in v0.13.6

func FromUvarint(buf []byte) (uint64, int, error)

FromUvarint reads an unsigned varint from the beginning of buf, returns the varint, and the number of bytes read.

func GenerateAssetId

func GenerateAssetId(assetKey string) crypto.Hash

func PutUvarint added in v0.13.6

func PutUvarint(buf []byte, x uint64) int

PutUvarint is an alias for binary.PutUvarint.

This is provided for convenience so users of this library can avoid built-in varint functions and easily audit code for uses of those functions.

Make sure that x is smaller or equal to MaxValueUvarint63, otherwise this function will produce values that may be rejected by readers.

func ReadUvarint added in v0.13.6

func ReadUvarint(r io.ByteReader) (uint64, error)

ReadUvarint reads a unsigned varint from the given reader.

func ToUvarint added in v0.13.6

func ToUvarint(num uint64) []byte

ToUvarint converts an unsigned integer to a varint-encoded []byte

func UvarintSize added in v0.13.6

func UvarintSize(num uint64) int

UvarintSize returns the size (in bytes) of `num` encoded as a unsigned varint.

This may return a size greater than MaxUvarintLen63, which would be an illegal value, and would be rejected by readers.

func ValidateChecksum added in v0.13.6

func ValidateChecksum(ingest, expect []byte) bool

ValidateChecksum returns true if the checksum of `ingest` is equal to `expected`>

func VerifyAddress

func VerifyAddress(addr string) error

func VerifyAssetKey

func VerifyAssetKey(assetKey string) error

func VerifyTransactionHash

func VerifyTransactionHash(hash string) error

Types

type Address added in v0.13.6

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

Address is the go type that represents an address in the filecoin network.

func NewBLSAddress added in v0.13.6

func NewBLSAddress(pubkey []byte) (Address, error)

NewBLSAddress returns an address using the BLS protocol.

func NewFromBytes added in v0.13.6

func NewFromBytes(addr []byte) (Address, error)

NewFromBytes return the address represented by the bytes `addr`.

func NewFromString added in v0.13.6

func NewFromString(addr string) (Address, error)

NewFromString returns the address represented by the string `addr`.

func NewSecp256k1Address added in v0.13.6

func NewSecp256k1Address(pubkey []byte) (Address, error)

NewSecp256k1Address returns an address using the SECP256K1 protocol.

func (Address) Bytes added in v0.13.6

func (a Address) Bytes() []byte

Bytes returns the address as bytes.

func (Address) Empty added in v0.13.6

func (a Address) Empty() bool

Empty returns true if the address is empty, false otherwise.

func (Address) Payload added in v0.13.6

func (a Address) Payload() []byte

Payload returns the payload of the address.

func (Address) Protocol added in v0.13.6

func (a Address) Protocol() Protocol

Protocol returns the protocol used by the address.

func (Address) String added in v0.13.6

func (a Address) String() string

String returns an address encoded as a string.

type Network added in v0.13.6

type Network = byte

Network represents which network an address belongs to.

const (
	// Mainnet is the main network.
	Mainnet Network = iota
)

type Protocol added in v0.13.6

type Protocol = byte

Protocol represents which protocol an address uses.

const (
	// ID represents the address ID protocol.
	ID Protocol = iota
	// SECP256K1 represents the address SECP256K1 protocol.
	SECP256K1
	// Actor represents the address Actor protocol.
	Actor
	// BLS represents the address BLS protocol.
	BLS

	Unknown = Protocol(255)
)

Jump to

Keyboard shortcuts

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