crypto

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package crypto handles all cryptographic types and operations associated with Aptos. It mainly handles signing, verification, parsing, and key generation.

Index

Constants

View Source
const AuthenticationKeyLength = 32

AuthenticationKeyLength is the length of a SHA3-256 Hash

View Source
const MultiEd25519BitmapLen = 4

MultiEd25519BitmapLen is the size of the bitmap representing who signed the transaction

View Source
const MultiKeyBitmapSize = uint32(4)

MultiKeyBitmapSize represents the 4 bytes needed to make a 32-bit bitmap

View Source
const Secp256k1PrivateKeyLength = 32
View Source
const Secp256k1PublicKeyLength = 65

Secp256k1PublicKeyLength we use the uncompressed version

View Source
const Secp256k1SignatureLength = ethCrypto.SignatureLength - 1

Secp256k1SignatureLength is the Secp256k1 signature without the recovery bit

Variables

This section is empty.

Functions

func KeyIndices

func KeyIndices(index uint8) (numByte uint8, numBit uint8)

KeyIndices determines the byte and bit set in the bitmap

Types

type AccountAuthenticator

type AccountAuthenticator struct {
	Variant AccountAuthenticatorType
	Auth    AccountAuthenticatorImpl
}

AccountAuthenticator a generic authenticator type for a transaction Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*AccountAuthenticator) MarshalBCS

func (ea *AccountAuthenticator) MarshalBCS(ser *bcs.Serializer)

func (*AccountAuthenticator) PubKey

func (ea *AccountAuthenticator) PubKey() PublicKey

func (*AccountAuthenticator) Signature

func (ea *AccountAuthenticator) Signature() Signature

func (*AccountAuthenticator) UnmarshalBCS

func (ea *AccountAuthenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*AccountAuthenticator) Verify

func (ea *AccountAuthenticator) Verify(data []byte) bool

type AccountAuthenticatorImpl

type AccountAuthenticatorImpl interface {
	bcs.Struct

	// PublicKey is the public key that can be used to verify the signature.  It must be a valid on-chain representation
	// and cannot be something like Secp256k1PublicKey on its own.
	PublicKey() PublicKey

	// Signature is a typed signature that can be verified by the public key. It must be a valid on-chain representation
	//	// and cannot be something like Secp256k1Signature on its own.
	Signature() Signature

	// Verify Return true if the AccountAuthenticator can be cryptographically verified
	Verify(data []byte) bool
}

AccountAuthenticatorImpl an implementation of an authenticator to provide generic verification across multiple types

type AccountAuthenticatorType

type AccountAuthenticatorType uint8

AccountAuthenticatorType single byte representing the spot in the enum from the Rust implementation

const (
	AccountAuthenticatorEd25519      AccountAuthenticatorType = 0
	AccountAuthenticatorMultiEd25519 AccountAuthenticatorType = 1
	AccountAuthenticatorSingleSender AccountAuthenticatorType = 2
	AccountAuthenticatorMultiKey     AccountAuthenticatorType = 3
)

type AnyPublicKey

type AnyPublicKey struct {
	Variant AnyPublicKeyVariant
	PubKey  VerifyingKey
}

AnyPublicKey is used by SingleSigner and MultiKey to allow for using different keys with the same structs Implements VerifyingKey, PublicKey, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func ToAnyPublicKey

func ToAnyPublicKey(key VerifyingKey) *AnyPublicKey

func (*AnyPublicKey) AuthKey

func (key *AnyPublicKey) AuthKey() *AuthenticationKey

func (*AnyPublicKey) Bytes

func (key *AnyPublicKey) Bytes() []byte

func (*AnyPublicKey) FromBytes

func (key *AnyPublicKey) FromBytes(bytes []byte) (err error)

func (*AnyPublicKey) FromHex

func (key *AnyPublicKey) FromHex(hexStr string) (err error)

func (*AnyPublicKey) MarshalBCS

func (key *AnyPublicKey) MarshalBCS(ser *bcs.Serializer)

func (*AnyPublicKey) Scheme

func (key *AnyPublicKey) Scheme() uint8

func (*AnyPublicKey) ToHex

func (key *AnyPublicKey) ToHex() string

func (*AnyPublicKey) UnmarshalBCS

func (key *AnyPublicKey) UnmarshalBCS(des *bcs.Deserializer)

func (*AnyPublicKey) Verify

func (key *AnyPublicKey) Verify(msg []byte, sig Signature) bool

type AnyPublicKeyVariant

type AnyPublicKeyVariant uint32

AnyPublicKeyVariant is an enum ID for the public key used in AnyPublicKey

const (
	AnyPublicKeyVariantEd25519   AnyPublicKeyVariant = 0
	AnyPublicKeyVariantSecp256k1 AnyPublicKeyVariant = 1
)

type AnySignature

type AnySignature struct {
	Variant   AnySignatureVariant
	Signature Signature
}

AnySignature is a wrapper around signatures signed with SingleSigner and verified with AnyPublicKey Implements Signature, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*AnySignature) Bytes

func (e *AnySignature) Bytes() []byte

func (*AnySignature) FromBytes

func (e *AnySignature) FromBytes(bytes []byte) (err error)

func (*AnySignature) FromHex

func (e *AnySignature) FromHex(hexStr string) (err error)

func (*AnySignature) MarshalBCS

func (e *AnySignature) MarshalBCS(ser *bcs.Serializer)

func (*AnySignature) ToHex

func (e *AnySignature) ToHex() string

func (*AnySignature) UnmarshalBCS

func (e *AnySignature) UnmarshalBCS(des *bcs.Deserializer)

type AnySignatureVariant

type AnySignatureVariant uint32

AnySignatureVariant is an enum ID for the signature used in AnySignature

const (
	AnySignatureVariantEd25519   AnySignatureVariant = 0
	AnySignatureVariantSecp256k1 AnySignatureVariant = 1
)

type AuthenticationKey

type AuthenticationKey [AuthenticationKeyLength]byte

AuthenticationKey a hash representing the method for authorizing an account Implements CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*AuthenticationKey) Bytes

func (ak *AuthenticationKey) Bytes() []byte

func (*AuthenticationKey) FromBytes

func (ak *AuthenticationKey) FromBytes(bytes []byte) (err error)

func (*AuthenticationKey) FromBytesAndScheme

func (ak *AuthenticationKey) FromBytesAndScheme(bytes []byte, scheme DeriveScheme)

FromBytesAndScheme derives the AuthenticationKey directly from the SHA3-256 hash of the combined array

func (*AuthenticationKey) FromHex

func (ak *AuthenticationKey) FromHex(hexStr string) (err error)

func (*AuthenticationKey) FromPublicKey

func (ak *AuthenticationKey) FromPublicKey(publicKey PublicKey)

FromPublicKey for private / public key pairs, the authentication key is derived from the public key directly

func (*AuthenticationKey) MarshalBCS

func (ak *AuthenticationKey) MarshalBCS(ser *bcs.Serializer)

func (*AuthenticationKey) ToHex

func (ak *AuthenticationKey) ToHex() string

func (*AuthenticationKey) UnmarshalBCS

func (ak *AuthenticationKey) UnmarshalBCS(des *bcs.Deserializer)

type CryptoMaterial

type CryptoMaterial interface {
	// Bytes outputs the raw byte representation of the CryptoMaterial
	Bytes() []byte

	// FromBytes loads the CryptoMaterial from the raw bytes
	FromBytes([]byte) error

	// ToHex outputs the hex representation of the CryptoMaterial with a leading `0x`
	ToHex() string

	// FromHex parses the hex representation of the CryptoMaterial with or without a leading `0x`
	FromHex(string) error
}

CryptoMaterial is a set of functions for serializing and deserializing a key to and from bytes and hex This mirrors the trait in Rust

type DeriveScheme

type DeriveScheme = uint8

DeriveScheme is the key type for deriving the AuthenticationKey. It is used in a SHA3-256 hash.

const (
	Ed25519Scheme         DeriveScheme = 0
	MultiEd25519Scheme    DeriveScheme = 1
	SingleKeyScheme       DeriveScheme = 2
	MultiKeyScheme        DeriveScheme = 3
	DeriveObjectScheme    DeriveScheme = 252
	NamedObjectScheme     DeriveScheme = 254
	ResourceAccountScheme DeriveScheme = 255
)

Seeds for deriving addresses from addresses

type Ed25519Authenticator

type Ed25519Authenticator struct {
	PubKey *Ed25519PublicKey
	Sig    *Ed25519Signature
}

Ed25519Authenticator represents a verifiable signature with it's accompanied public key Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Ed25519Authenticator) MarshalBCS

func (ea *Ed25519Authenticator) MarshalBCS(ser *bcs.Serializer)

func (*Ed25519Authenticator) PublicKey

func (ea *Ed25519Authenticator) PublicKey() PublicKey

func (*Ed25519Authenticator) Signature

func (ea *Ed25519Authenticator) Signature() Signature

func (*Ed25519Authenticator) UnmarshalBCS

func (ea *Ed25519Authenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*Ed25519Authenticator) Verify

func (ea *Ed25519Authenticator) Verify(msg []byte) bool

type Ed25519PrivateKey

type Ed25519PrivateKey struct {
	Inner ed25519.PrivateKey
}

Ed25519PrivateKey represents an Ed25519Private key Implements Signer, MessageSigner, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func GenerateEd25519PrivateKey

func GenerateEd25519PrivateKey(rand ...io.Reader) (privateKey *Ed25519PrivateKey, err error)

GenerateEd25519PrivateKey generates a random Ed25519 private key

func (*Ed25519PrivateKey) AuthKey

func (key *Ed25519PrivateKey) AuthKey() *AuthenticationKey

func (*Ed25519PrivateKey) Bytes

func (key *Ed25519PrivateKey) Bytes() []byte

func (*Ed25519PrivateKey) FromBytes

func (key *Ed25519PrivateKey) FromBytes(bytes []byte) (err error)

func (*Ed25519PrivateKey) FromHex

func (key *Ed25519PrivateKey) FromHex(hexStr string) (err error)

func (*Ed25519PrivateKey) PubKey

func (key *Ed25519PrivateKey) PubKey() PublicKey

func (*Ed25519PrivateKey) Sign

func (key *Ed25519PrivateKey) Sign(msg []byte) (authenticator *AccountAuthenticator, err error)

func (*Ed25519PrivateKey) SignMessage

func (key *Ed25519PrivateKey) SignMessage(msg []byte) (sig Signature, err error)

func (*Ed25519PrivateKey) ToHex

func (key *Ed25519PrivateKey) ToHex() string

func (*Ed25519PrivateKey) VerifyingKey

func (key *Ed25519PrivateKey) VerifyingKey() VerifyingKey

type Ed25519PublicKey

type Ed25519PublicKey struct {
	Inner ed25519.PublicKey
}

Ed25519PublicKey is a Ed25519PublicKey which can be used to verify signatures Implements VerifyingKey, PublicKey, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Ed25519PublicKey) AuthKey

func (key *Ed25519PublicKey) AuthKey() *AuthenticationKey

func (*Ed25519PublicKey) Bytes

func (key *Ed25519PublicKey) Bytes() []byte

func (*Ed25519PublicKey) FromBytes

func (key *Ed25519PublicKey) FromBytes(bytes []byte) (err error)

func (*Ed25519PublicKey) FromHex

func (key *Ed25519PublicKey) FromHex(hexStr string) (err error)

func (*Ed25519PublicKey) MarshalBCS

func (key *Ed25519PublicKey) MarshalBCS(ser *bcs.Serializer)

func (*Ed25519PublicKey) Scheme

func (key *Ed25519PublicKey) Scheme() uint8

func (*Ed25519PublicKey) ToHex

func (key *Ed25519PublicKey) ToHex() string

func (*Ed25519PublicKey) UnmarshalBCS

func (key *Ed25519PublicKey) UnmarshalBCS(des *bcs.Deserializer)

func (*Ed25519PublicKey) Verify

func (key *Ed25519PublicKey) Verify(msg []byte, sig Signature) bool

type Ed25519Signature

type Ed25519Signature struct {
	Inner [ed25519.SignatureSize]byte
}

Ed25519Signature a wrapper for serialization of Ed25519 signatures Implements Signature, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Ed25519Signature) Bytes

func (e *Ed25519Signature) Bytes() []byte

func (*Ed25519Signature) FromBytes

func (e *Ed25519Signature) FromBytes(bytes []byte) (err error)

func (*Ed25519Signature) FromHex

func (e *Ed25519Signature) FromHex(hexStr string) (err error)

func (*Ed25519Signature) MarshalBCS

func (e *Ed25519Signature) MarshalBCS(ser *bcs.Serializer)

func (*Ed25519Signature) ToHex

func (e *Ed25519Signature) ToHex() string

func (*Ed25519Signature) UnmarshalBCS

func (e *Ed25519Signature) UnmarshalBCS(des *bcs.Deserializer)

type MessageSigner

type MessageSigner interface {
	// SignMessage signs a message and returns the raw signature without a key
	SignMessage(msg []byte) (signature Signature, err error)

	// VerifyingKey Retrieve the public key for signature verification
	VerifyingKey() VerifyingKey
}

MessageSigner a generic interface for a signing private key, a private key isn't always a signer, see SingleSender This is not BCS serializable, because this doesn't go on-chain

type MultiEd25519Authenticator

type MultiEd25519Authenticator struct {
	PubKey *MultiEd25519PublicKey
	Sig    *MultiEd25519Signature
}

MultiEd25519Authenticator is an authenticator for a MultiEd25519Signature Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiEd25519Authenticator) MarshalBCS

func (ea *MultiEd25519Authenticator) MarshalBCS(ser *bcs.Serializer)

func (*MultiEd25519Authenticator) PublicKey

func (ea *MultiEd25519Authenticator) PublicKey() PublicKey

func (*MultiEd25519Authenticator) Signature

func (ea *MultiEd25519Authenticator) Signature() Signature

func (*MultiEd25519Authenticator) UnmarshalBCS

func (ea *MultiEd25519Authenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*MultiEd25519Authenticator) Verify

func (ea *MultiEd25519Authenticator) Verify(msg []byte) bool

type MultiEd25519PublicKey

type MultiEd25519PublicKey struct {
	// PubKeys is the list of all public keys associated with the off-chain multi-sig
	PubKeys []*Ed25519PublicKey
	// SignaturesRequired is the number of signatures required to pass verification
	SignaturesRequired uint8
}

MultiEd25519PublicKey is the public key for off-chain multi-sig on Aptos with Ed25519 keys Implements VerifyingKey, PublicKey, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiEd25519PublicKey) AuthKey

func (key *MultiEd25519PublicKey) AuthKey() *AuthenticationKey

func (*MultiEd25519PublicKey) Bytes

func (key *MultiEd25519PublicKey) Bytes() []byte

func (*MultiEd25519PublicKey) FromBytes

func (key *MultiEd25519PublicKey) FromBytes(bytes []byte) (err error)

func (*MultiEd25519PublicKey) FromHex

func (key *MultiEd25519PublicKey) FromHex(hexStr string) (err error)

func (*MultiEd25519PublicKey) MarshalBCS

func (key *MultiEd25519PublicKey) MarshalBCS(ser *bcs.Serializer)

func (*MultiEd25519PublicKey) Scheme

func (key *MultiEd25519PublicKey) Scheme() uint8

func (*MultiEd25519PublicKey) ToHex

func (key *MultiEd25519PublicKey) ToHex() string

func (*MultiEd25519PublicKey) UnmarshalBCS

func (key *MultiEd25519PublicKey) UnmarshalBCS(des *bcs.Deserializer)

func (*MultiEd25519PublicKey) Verify

func (key *MultiEd25519PublicKey) Verify(msg []byte, signature Signature) bool

type MultiEd25519Signature

type MultiEd25519Signature struct {
	Signatures []*Ed25519Signature
	Bitmap     [MultiEd25519BitmapLen]byte
}

MultiEd25519Signature is a signature for off-chain multi-sig Implements Signature, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiEd25519Signature) Bytes

func (e *MultiEd25519Signature) Bytes() []byte

func (*MultiEd25519Signature) FromBytes

func (e *MultiEd25519Signature) FromBytes(bytes []byte) (err error)

func (*MultiEd25519Signature) FromHex

func (e *MultiEd25519Signature) FromHex(hexStr string) (err error)

func (*MultiEd25519Signature) MarshalBCS

func (e *MultiEd25519Signature) MarshalBCS(ser *bcs.Serializer)

func (*MultiEd25519Signature) ToHex

func (e *MultiEd25519Signature) ToHex() string

func (*MultiEd25519Signature) UnmarshalBCS

func (e *MultiEd25519Signature) UnmarshalBCS(des *bcs.Deserializer)

type MultiKey

type MultiKey struct {
	PubKeys            []*AnyPublicKey
	SignaturesRequired uint8
}

MultiKey is an off-chain multisig, where multiple different keys can be used together to create an account Implements VerifyingKey, PublicKey, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiKey) AuthKey

func (key *MultiKey) AuthKey() *AuthenticationKey

func (*MultiKey) Bytes

func (key *MultiKey) Bytes() []byte

func (*MultiKey) FromBytes

func (key *MultiKey) FromBytes(bytes []byte) (err error)

func (*MultiKey) FromHex

func (key *MultiKey) FromHex(hexStr string) (err error)

func (*MultiKey) MarshalBCS

func (key *MultiKey) MarshalBCS(ser *bcs.Serializer)

func (*MultiKey) Scheme

func (key *MultiKey) Scheme() uint8

func (*MultiKey) ToHex

func (key *MultiKey) ToHex() string

func (*MultiKey) UnmarshalBCS

func (key *MultiKey) UnmarshalBCS(des *bcs.Deserializer)

func (*MultiKey) Verify

func (key *MultiKey) Verify(msg []byte, signature Signature) bool

type MultiKeyAuthenticator

type MultiKeyAuthenticator struct {
	PubKey *MultiKey
	Sig    *MultiKeySignature
}

MultiKeyAuthenticator is an on-chain authenticator for a MultiKeySignature Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiKeyAuthenticator) MarshalBCS

func (ea *MultiKeyAuthenticator) MarshalBCS(ser *bcs.Serializer)

func (*MultiKeyAuthenticator) PublicKey

func (ea *MultiKeyAuthenticator) PublicKey() PublicKey

func (*MultiKeyAuthenticator) Signature

func (ea *MultiKeyAuthenticator) Signature() Signature

func (*MultiKeyAuthenticator) UnmarshalBCS

func (ea *MultiKeyAuthenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*MultiKeyAuthenticator) Verify

func (ea *MultiKeyAuthenticator) Verify(msg []byte) bool

type MultiKeyBitmap

type MultiKeyBitmap [MultiKeyBitmapSize]byte

MultiKeyBitmap represents a bitmap of signatures in a MultiKey public key that signed the transaction There are a maximum of 32 possible values in MultiKeyBitmapSize, starting from the leftmost bit representing index 0 of the public key

func (*MultiKeyBitmap) AddKey

func (bm *MultiKeyBitmap) AddKey(index uint8) error

AddKey adds the value to the map, returning an error if it is already added

func (*MultiKeyBitmap) ContainsKey

func (bm *MultiKeyBitmap) ContainsKey(index uint8) bool

ContainsKey tells us if the current index is in the map

func (*MultiKeyBitmap) MarshalBCS

func (bm *MultiKeyBitmap) MarshalBCS(ser *bcs.Serializer)

func (*MultiKeyBitmap) UnmarshalBCS

func (bm *MultiKeyBitmap) UnmarshalBCS(des *bcs.Deserializer)

type MultiKeySignature

type MultiKeySignature struct {
	Signatures []*AnySignature
	Bitmap     MultiKeyBitmap
}

MultiKeySignature is an off-chain multi-sig signature that can be verified by a MultiKey Implements Signature, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*MultiKeySignature) Bytes

func (e *MultiKeySignature) Bytes() []byte

func (*MultiKeySignature) FromBytes

func (e *MultiKeySignature) FromBytes(bytes []byte) (err error)

func (*MultiKeySignature) FromHex

func (e *MultiKeySignature) FromHex(hexStr string) (err error)

func (*MultiKeySignature) MarshalBCS

func (e *MultiKeySignature) MarshalBCS(ser *bcs.Serializer)

func (*MultiKeySignature) ToHex

func (e *MultiKeySignature) ToHex() string

func (*MultiKeySignature) UnmarshalBCS

func (e *MultiKeySignature) UnmarshalBCS(des *bcs.Deserializer)

type PublicKey

type PublicKey interface {
	VerifyingKey

	// AuthKey gives the AuthenticationKey associated with the public key
	AuthKey() *AuthenticationKey

	// Scheme The scheme used for address derivation
	Scheme() DeriveScheme
}

PublicKey is an interface for a public key that can be used to verify transactions in a TransactionAuthenticator

type Secp256k1Authenticator

type Secp256k1Authenticator struct {
	PubKey *Secp256k1PublicKey
	Sig    *Secp256k1Signature
}

Secp256k1Authenticator is the authenticator for Secp256k1, but it cannot stand on its own and must be used with SingleKeyAuthenticator Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Secp256k1Authenticator) MarshalBCS

func (ea *Secp256k1Authenticator) MarshalBCS(ser *bcs.Serializer)

func (*Secp256k1Authenticator) PublicKey

func (ea *Secp256k1Authenticator) PublicKey() VerifyingKey

func (*Secp256k1Authenticator) Signature

func (ea *Secp256k1Authenticator) Signature() Signature

func (*Secp256k1Authenticator) UnmarshalBCS

func (ea *Secp256k1Authenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*Secp256k1Authenticator) Verify

func (ea *Secp256k1Authenticator) Verify(msg []byte) bool

type Secp256k1PrivateKey

type Secp256k1PrivateKey struct {
	Inner *ecdsa.PrivateKey
}

Secp256k1PrivateKey is a private key that can be used with SingleSigner. It cannot stand on its own. Implements MessageSigner, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func GenerateSecp256k1Key

func GenerateSecp256k1Key() (*Secp256k1PrivateKey, error)

func (*Secp256k1PrivateKey) Bytes

func (key *Secp256k1PrivateKey) Bytes() []byte

func (*Secp256k1PrivateKey) FromBytes

func (key *Secp256k1PrivateKey) FromBytes(bytes []byte) (err error)

func (*Secp256k1PrivateKey) FromHex

func (key *Secp256k1PrivateKey) FromHex(hexStr string) (err error)

func (*Secp256k1PrivateKey) SignMessage

func (key *Secp256k1PrivateKey) SignMessage(msg []byte) (sig Signature, err error)

func (*Secp256k1PrivateKey) ToHex

func (key *Secp256k1PrivateKey) ToHex() string

func (*Secp256k1PrivateKey) VerifyingKey

func (key *Secp256k1PrivateKey) VerifyingKey() VerifyingKey

type Secp256k1PublicKey

type Secp256k1PublicKey struct {
	Inner *ecdsa.PublicKey
}

Secp256k1PublicKey is the corresponding public key for Secp256k1PrivateKey, it cannot be used on its own Implements VerifyingKey, PublicKey, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Secp256k1PublicKey) Bytes

func (key *Secp256k1PublicKey) Bytes() []byte

func (*Secp256k1PublicKey) FromBytes

func (key *Secp256k1PublicKey) FromBytes(bytes []byte) (err error)

func (*Secp256k1PublicKey) FromHex

func (key *Secp256k1PublicKey) FromHex(hexStr string) (err error)

func (*Secp256k1PublicKey) MarshalBCS

func (key *Secp256k1PublicKey) MarshalBCS(ser *bcs.Serializer)

func (*Secp256k1PublicKey) ToHex

func (key *Secp256k1PublicKey) ToHex() string

func (*Secp256k1PublicKey) UnmarshalBCS

func (key *Secp256k1PublicKey) UnmarshalBCS(des *bcs.Deserializer)

func (*Secp256k1PublicKey) Verify

func (key *Secp256k1PublicKey) Verify(msg []byte, sig Signature) bool

type Secp256k1Signature

type Secp256k1Signature struct {
	Inner []byte
}

Secp256k1Signature a wrapper for serialization of Secp256k1 signatures Implements Signature, CryptoMaterial, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*Secp256k1Signature) Bytes

func (e *Secp256k1Signature) Bytes() []byte

func (*Secp256k1Signature) FromBytes

func (e *Secp256k1Signature) FromBytes(bytes []byte) (err error)

func (*Secp256k1Signature) FromHex

func (e *Secp256k1Signature) FromHex(hexStr string) (err error)

func (*Secp256k1Signature) MarshalBCS

func (e *Secp256k1Signature) MarshalBCS(ser *bcs.Serializer)

func (*Secp256k1Signature) ToHex

func (e *Secp256k1Signature) ToHex() string

func (*Secp256k1Signature) UnmarshalBCS

func (e *Secp256k1Signature) UnmarshalBCS(des *bcs.Deserializer)

type Signature

type Signature interface {
	bcs.Struct
	CryptoMaterial
}

Signature is an identifier for a serializable Signature for on-chain representation

type Signer

type Signer interface {
	// Sign signs a transaction and returns an associated authenticator
	Sign(msg []byte) (authenticator *AccountAuthenticator, err error)

	// SignMessage signs a message and returns the raw signature without a key
	SignMessage(msg []byte) (signature Signature, err error)

	// AuthKey gives the AuthenticationKey associated with the signer
	AuthKey() *AuthenticationKey

	// PubKey Retrieve the public key for signature verification
	PubKey() PublicKey
}

Signer a generic interface for any kind of signing

type SingleKeyAuthenticator

type SingleKeyAuthenticator struct {
	PubKey *AnyPublicKey
	Sig    *AnySignature
}

SingleKeyAuthenticator is an authenticator for a SingleSigner Implements AccountAuthenticatorImpl, bcs.Marshaler, bcs.Unmarshaler, bcs.Struct

func (*SingleKeyAuthenticator) MarshalBCS

func (ea *SingleKeyAuthenticator) MarshalBCS(ser *bcs.Serializer)

func (*SingleKeyAuthenticator) PublicKey

func (ea *SingleKeyAuthenticator) PublicKey() PublicKey

func (*SingleKeyAuthenticator) Signature

func (ea *SingleKeyAuthenticator) Signature() Signature

func (*SingleKeyAuthenticator) UnmarshalBCS

func (ea *SingleKeyAuthenticator) UnmarshalBCS(des *bcs.Deserializer)

func (*SingleKeyAuthenticator) Verify

func (ea *SingleKeyAuthenticator) Verify(msg []byte) bool

type SingleSigner

type SingleSigner struct {
	Signer MessageSigner
}

SingleSigner is a wrapper around different types of MessageSigners to allow for many types of keys Implements Signer, MessageSigner

func NewSingleSigner

func NewSingleSigner(input MessageSigner) *SingleSigner

func (*SingleSigner) AuthKey

func (key *SingleSigner) AuthKey() *AuthenticationKey

func (*SingleSigner) PubKey

func (key *SingleSigner) PubKey() PublicKey

func (*SingleSigner) Sign

func (key *SingleSigner) Sign(msg []byte) (authenticator *AccountAuthenticator, err error)

func (*SingleSigner) SignMessage

func (key *SingleSigner) SignMessage(msg []byte) (Signature, error)

SignMessage similar, but doesn't implement MessageSigner so there's no circular usage

type VerifyingKey

type VerifyingKey interface {
	bcs.Struct
	CryptoMaterial

	// Verify verifies a message with the public key
	Verify(msg []byte, sig Signature) bool
}

VerifyingKey a generic interface for a public key associated with the private key, but it cannot necessarily stand on its own as a public key for authentication on Aptos

Jump to

Keyboard shortcuts

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