cryptography

package
v0.0.0-...-cf383d1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const HashLength = 32

HashLength const

View Source
const HexPrefix = "0x"

HexPrefix const

View Source
const Length = 34

Length is the length of data

View Source
const PrivateKeyLength = 32

PrivateKeyLength defines the length of a private key

Variables

View Source
var Null []byte = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0}

Functions

func IsValidAddress

func IsValidAddress(text string) bool

IsValidAddress verifies if a string is a valid address

Types

type Address

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

Address struct

func FromKey

func FromKey(keyPair KeyPair) Address

FromKey generates an address from a KeyPair

func FromString

func FromString(s string) (Address, error)

FromString creates an instance of an Address from a string

func NewAddress

func NewAddress(pubKey []byte) Address

NewAddress returns a new Address object

func NullAddress

func NullAddress() Address

NullAddress returns a new null Address object

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns the data representing an address

func (Address) BytesPrefixed

func (a Address) BytesPrefixed() []byte

BytesPrefixed returns the data representing an address, including prefix required for binary serialization

func (*Address) Deserialize

func (a *Address) Deserialize(reader *io.BinReader)

Deserialize implements ther Serializable interface

func (*Address) GetPublicKey

func (a *Address) GetPublicKey() []byte

func (Address) IsNull

func (a Address) IsNull() bool

IsNull checks if the Address represents a nil Address

func (Address) IsUser

func (a Address) IsUser() bool

IsUser verifies if the passed in address is a user address

func (Address) Kind

func (a Address) Kind() AddressKind

Kind returns the kind of an address

func (*Address) Serialize

func (a *Address) Serialize(writer *io.BinWriter)

Serialize implements ther Serializable interface

func (Address) String

func (a Address) String() string

String creates the a base58 encoded representation of the address including the address prefix

func (Address) Text

func (a Address) Text() string

Text returns (and initializes if needed) raw text representation of the address. For null address it returns nil. In most cases use String() instead to get text address, which returns "NULL" string for null addresses.

type AddressKind

type AddressKind byte

AddressKind type

const (
	// Invalid address
	Invalid AddressKind = 0x00
	// User address
	User AddressKind = 0x01
	// System address
	System AddressKind = 0x02
	// Interop address
	Interop AddressKind = 0x03
)

type Ed25519Signature

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

Ed25519Signature struct

func Generate

func Generate(keyPair KeyPair, message []byte) Ed25519Signature

Generate a new signature

func NewEd25519Signature

func NewEd25519Signature(bytes []byte) Ed25519Signature

NewEd25519Signature instatiates a new signature object

func (Ed25519Signature) Bytes

func (sig Ed25519Signature) Bytes() []byte

Bytes returns the byte representation of the signature

func (Ed25519Signature) Deserialize

func (sig Ed25519Signature) Deserialize(reader *io.BinReader)

Deserialize implements ther Serializable interface

func (Ed25519Signature) Kind

func (sig Ed25519Signature) Kind() SignatureKind

Kind returns the type of the signature

func (Ed25519Signature) Serialize

func (sig Ed25519Signature) Serialize(writer *io.BinWriter)

Serialize implements ther Serializable interface

func (Ed25519Signature) Verify

func (sig Ed25519Signature) Verify(message []byte, addresses []Address) bool

Verify verifies that the message was signed by one of the addresses passed in

type Hash

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

Hash struct

func HashFromBytes

func HashFromBytes(data []byte) (Hash, error)

HashFromBytes returns a Hash based on the passed in byte slice

func HashFromString

func HashFromString(s string) Hash

HashFromString creates an instance of Hash from a string

func ParseHash

func ParseHash(s string) (Hash, error)

ParseHash parses a string resulting in a Hash

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the bytes of the hash

func (*Hash) Deserialize

func (h *Hash) Deserialize(reader *io.BinReader)

Deserialize implements ther Serializable interface

func (Hash) FromUnpaddedHex

func (h Hash) FromUnpaddedHex(s string) (Hash, error)

FromUnpaddedHex creates an instance of Hash from an unpadded hex string

func (Hash) GetDifficulty

func (h Hash) GetDifficulty() int

GetDifficulty retrieves the current difficulty of the hash

func (Hash) IsNull

func (h Hash) IsNull() bool

IsNull checks if the Hash represents a nil hash

func (*Hash) Serialize

func (h *Hash) Serialize(writer *io.BinWriter)

Serialize implements ther Serializable interface

func (Hash) Size

func (h Hash) Size() int

Size returns the length of the underlying byte slice

func (Hash) String

func (h Hash) String() string

String creates the a base16 encoded representation of Hash

type Hashable

type Hashable interface {
	Hash() Hash
}

Hashable represents an object which can be hashed. Usually these objects are io.Serializable and signable. They tend to cache the hash inside for effectiveness, providing this accessor method. Anything that can be identified with a hash can then be signed and verified.

type KeyPair

type KeyPair interface {
	PrivateKey() []byte
	ExpandedPrivateKey() []byte
	PublicKey() []byte
	Address() Address

	Sign(msg []byte) Signature
}

KeyPair a

type PhantasmaKeys

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

PhantasmaKeys is the struct that holds the information about keys for the phantasma blockchain

func FromWIF

func FromWIF(wif string) (PhantasmaKeys, error)

FromWIF creates a new key pair based on the passed in WIF

func GeneratePhantasmaKeys

func GeneratePhantasmaKeys() PhantasmaKeys

GeneratePhantasmaKeys creates a new phantasma keypair

func NewPhantasmaKeys

func NewPhantasmaKeys(seed []byte) PhantasmaKeys

NewPhantasmaKeys instantiates a new PhantasmaKeys object based on the given seed

func (PhantasmaKeys) Address

func (k PhantasmaKeys) Address() Address

Address returns the associated address

func (PhantasmaKeys) ExpandedPrivateKey

func (k PhantasmaKeys) ExpandedPrivateKey() []byte

ExpandedPrivateKey returns the associated expanded private key

func (PhantasmaKeys) PrivateKey

func (k PhantasmaKeys) PrivateKey() []byte

PrivateKey returns the associated private key

func (PhantasmaKeys) PublicKey

func (k PhantasmaKeys) PublicKey() []byte

PublicKey returns the associated public key

func (PhantasmaKeys) Sign

func (k PhantasmaKeys) Sign(msg []byte) Signature

Sign generates a signature for the passed in message

func (PhantasmaKeys) String

func (k PhantasmaKeys) String() string

func (PhantasmaKeys) WIF

func (k PhantasmaKeys) WIF() string

WIF returns the WIF based on the private key

type Signature

type Signature interface {
	Kind() SignatureKind
	Verify(message []byte, addresses []Address) bool
	Serialize(*io.BinWriter)
	Deserialize(*io.BinReader)
	Bytes() []byte
}

Signature a

type SignatureKind

type SignatureKind uint

SignatureKind type

const (
	// None Signature
	None SignatureKind = iota
	// Ed25519 Signature
	Ed25519
	// ECDSA Signature
	ECDSA
	// Ring Signature
	Ring
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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