crypto

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

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 number of bytes in the bitmap representing who signed the transaction

View Source
const MultiKeyBitmapSize = uint8(4)

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

View Source
const Secp256k1PrivateKeyLength = 32

Secp256k1PrivateKeyLength is the Secp256k1PrivateKey length in bytes

View Source
const Secp256k1PublicKeyLength = 65

Secp256k1PublicKeyLength is the Secp256k1PublicKey length in bytes. We use the uncompressed version.

View Source
const Secp256k1SignatureLength = ethCrypto.SignatureLength - 1

Secp256k1SignatureLength is the Secp256k1Signature length in bytes. It is a 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 // Variant is the type of authenticator
	Auth    AccountAuthenticatorImpl // Auth is the actual authenticator
}

AccountAuthenticator a generic authenticator type for a transaction

Implements:

func (*AccountAuthenticator) FromKeyAndSignature added in v0.7.0

func (ea *AccountAuthenticator) FromKeyAndSignature(key PublicKey, sig Signature) error

func (*AccountAuthenticator) MarshalBCS

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

MarshalBCS serializes the AccountAuthenticator to the BCS format

Implements:

func (*AccountAuthenticator) PubKey

func (ea *AccountAuthenticator) PubKey() PublicKey

PubKey returns the public key of the authenticator

func (*AccountAuthenticator) Signature

func (ea *AccountAuthenticator) Signature() Signature

Signature returns the signature of the authenticator

func (*AccountAuthenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the AccountAuthenticator from the BCS format

Implements:

func (*AccountAuthenticator) Verify

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

Verify returns true if the authenticator can be cryptographically verified

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.

Types:

type AccountAuthenticatorType

type AccountAuthenticatorType uint8

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

const (
	AccountAuthenticatorEd25519      AccountAuthenticatorType = 0 // AccountAuthenticatorEd25519 is the authenticator type for ed25519 accounts
	AccountAuthenticatorMultiEd25519 AccountAuthenticatorType = 1 // AccountAuthenticatorMultiEd25519 is the authenticator type for multi-ed25519 accounts
	AccountAuthenticatorSingleSender AccountAuthenticatorType = 2 // AccountAuthenticatorSingleSender is the authenticator type for single-key accounts
	AccountAuthenticatorMultiKey     AccountAuthenticatorType = 3 // AccountAuthenticatorMultiKey is the authenticator type for multi-key accounts
)

type AnyPublicKey

type AnyPublicKey struct {
	Variant AnyPublicKeyVariant // Variant is the type of public key
	PubKey  VerifyingKey        // PubKey is the actual public key
}

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, error)

ToAnyPublicKey converts a VerifyingKey to an AnyPublicKey

func (*AnyPublicKey) AuthKey

func (key *AnyPublicKey) AuthKey() *AuthenticationKey

AuthKey converts the public key to an authentication key

Implements:

func (*AnyPublicKey) Bytes

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

Bytes returns the raw bytes of the AnyPublicKey

Implements:

func (*AnyPublicKey) FromBytes

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

FromBytes sets the AnyPublicKey to the given bytes

Implements:

func (*AnyPublicKey) FromHex

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

FromHex sets the AnyPublicKey to the bytes represented by the hex string, with or without a leading 0x

Implements:

func (*AnyPublicKey) MarshalBCS

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

MarshalBCS serializes the AnyPublicKey to bytes

Implements:

func (*AnyPublicKey) Scheme

func (key *AnyPublicKey) Scheme() uint8

Scheme returns the scheme for the public key

Implements:

func (*AnyPublicKey) ToHex

func (key *AnyPublicKey) ToHex() string

ToHex returns the hex string representation of the AnyPublicKey, with a leading 0x

Implements:

func (*AnyPublicKey) UnmarshalBCS

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

UnmarshalBCS deserializes the AnyPublicKey from bytes

Implements:

func (*AnyPublicKey) Verify

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

Verify verifies the signature against the message

Implements:

type AnyPublicKeyVariant

type AnyPublicKeyVariant uint32

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

const (
	AnyPublicKeyVariantEd25519   AnyPublicKeyVariant = 0 // AnyPublicKeyVariantEd25519 is the variant for [Ed25519PublicKey]
	AnyPublicKeyVariantSecp256k1 AnyPublicKeyVariant = 1 // AnyPublicKeyVariantSecp256k1 is the variant for [Secp256k1PublicKey]
)

type AnySignature

type AnySignature struct {
	Variant   AnySignatureVariant
	Signature Signature
}

AnySignature is a wrapper around signatures signed with SingleSigner and verified with AnyPublicKey

Implements:

func (*AnySignature) Bytes

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

Bytes returns the raw bytes of the AnySignature

Implements:

func (*AnySignature) FromBytes

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

FromBytes sets the AnySignature to the given bytes

Implements:

func (*AnySignature) FromHex

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

FromHex sets the AnySignature to the bytes represented by the hex string, with or without a leading 0x

Implements:

func (*AnySignature) MarshalBCS

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

MarshalBCS serializes the AnySignature to bytes

Implements:

func (*AnySignature) ToHex

func (e *AnySignature) ToHex() string

ToHex returns the hex string representation of the AnySignature, with a leading 0x

Implements:

func (*AnySignature) UnmarshalBCS

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

UnmarshalBCS deserializes the AnySignature from bytes

Implements:

type AnySignatureVariant

type AnySignatureVariant uint32

AnySignatureVariant is an enum ID for the signature used in AnySignature

const (
	AnySignatureVariantEd25519   AnySignatureVariant = 0 // AnySignatureVariantEd25519 is the variant for [Ed25519Signature]
	AnySignatureVariantSecp256k1 AnySignatureVariant = 1 // AnySignatureVariantSecp256k1 is the variant for [Secp256k1Signature]
)

type AuthenticationKey

type AuthenticationKey [AuthenticationKeyLength]byte

AuthenticationKey a hash representing the method for authorizing an account

Implements:

func (*AuthenticationKey) Bytes

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

Bytes returns the raw bytes of the AuthenticationKey

Implements:

func (*AuthenticationKey) FromBytes

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

FromBytes sets the AuthenticationKey to the given bytes

Implements:

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)

FromHex sets the AuthenticationKey to the bytes represented by the hex string, with or without a leading 0x

Implements:

func (*AuthenticationKey) FromPublicKey

func (ak *AuthenticationKey) FromPublicKey(publicKey PublicKey)

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

func (*AuthenticationKey) MarshalBCS

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

MarshalBCS serializes the AuthenticationKey to BCS bytes

Implements:

func (*AuthenticationKey) ToHex

func (ak *AuthenticationKey) ToHex() string

ToHex returns the hex string representation of the AuthenticationKey, with a leading 0x

Implements:

func (*AuthenticationKey) UnmarshalBCS

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

UnmarshalBCS deserializes the AuthenticationKey from BCS bytes

Implements:

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.

Types:

const (
	Ed25519Scheme         DeriveScheme = 0   // Ed25519Scheme is the default scheme for deriving the AuthenticationKey
	MultiEd25519Scheme    DeriveScheme = 1   // MultiEd25519Scheme is the scheme for deriving the AuthenticationKey for Multi-ed25519 accounts
	SingleKeyScheme       DeriveScheme = 2   // SingleKeyScheme is the scheme for deriving the AuthenticationKey for single-key accounts
	MultiKeyScheme        DeriveScheme = 3   // MultiKeyScheme is the scheme for deriving the AuthenticationKey for multi-key accounts
	DeriveObjectScheme    DeriveScheme = 252 // DeriveObjectScheme is the scheme for deriving the AuthenticationKey for objects, used to create new object addresses
	NamedObjectScheme     DeriveScheme = 254 // NamedObjectScheme is the scheme for deriving the AuthenticationKey for named objects, used to create new named object addresses
	ResourceAccountScheme DeriveScheme = 255 // ResourceAccountScheme is the scheme for deriving the AuthenticationKey for resource accounts, used to create new resource account addresses
)

Seeds for deriving addresses from addresses

type Ed25519Authenticator

type Ed25519Authenticator struct {
	PubKey *Ed25519PublicKey // PubKey is the public key
	Sig    *Ed25519Signature // Sig is the signature
}

Ed25519Authenticator represents a verifiable signature with it's accompanied public key

Implements:

func (*Ed25519Authenticator) MarshalBCS

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

MarshalBCS serializes the Ed25519Authenticator to BCS bytes

Implements:

func (*Ed25519Authenticator) PublicKey

func (ea *Ed25519Authenticator) PublicKey() PublicKey

PublicKey returns the PublicKey of the authenticator

Implements:

func (*Ed25519Authenticator) Signature

func (ea *Ed25519Authenticator) Signature() Signature

Signature returns the Signature of the authenticator

Implements:

func (*Ed25519Authenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the Ed25519Authenticator from BCS bytes

Sets bcs.Deserializer.Error if it fails to read the required bytes.

Implements:

func (*Ed25519Authenticator) Verify

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

Verify returns true if the authenticator can be cryptographically verified

Implements:

type Ed25519PrivateKey

type Ed25519PrivateKey struct {
	Inner ed25519.PrivateKey // Inner is the actual private key
}

Ed25519PrivateKey represents an Ed25519Private key

Implements:

func GenerateEd25519PrivateKey

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

GenerateEd25519PrivateKey generates a random Ed25519PrivateKey

An io.Reader can be provided for randomness, otherwise the default randomness source is from ed25519.GenerateKey. The io.Reader must provide 32 bytes of input.

Returns an error if the key generation fails.

func (*Ed25519PrivateKey) AuthKey

func (key *Ed25519PrivateKey) AuthKey() *AuthenticationKey

AuthKey returns the AuthenticationKey associated with the Ed25519PrivateKey for a Ed25519Scheme.

Implements:

func (*Ed25519PrivateKey) Bytes

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

Bytes returns the raw bytes of the Ed25519PrivateKey

Implements:

func (*Ed25519PrivateKey) EmptySignature added in v0.6.0

func (key *Ed25519PrivateKey) EmptySignature() Signature

EmptySignature creates an empty signature for use in simulation

Implements:

func (*Ed25519PrivateKey) FromBytes

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

FromBytes sets the Ed25519PrivateKey to the given bytes

Returns an error if the bytes length is not ed25519.SeedSize.

Implements:

func (*Ed25519PrivateKey) FromHex

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

FromHex sets the Ed25519PrivateKey to the bytes represented by the hex string, with or without a leading 0x

Errors if the hex string is not valid, or if the bytes length is not ed25519.SeedSize.

Implements:

func (*Ed25519PrivateKey) PubKey

func (key *Ed25519PrivateKey) PubKey() PublicKey

PubKey returns the Ed25519PublicKey associated with the Ed25519PrivateKey

Implements:

func (*Ed25519PrivateKey) Sign

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

Sign signs a message and returns an AccountAuthenticator with the Ed25519Signature and Ed25519PublicKey

Never returns an error.

Implements:

func (*Ed25519PrivateKey) SignMessage

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

SignMessage signs a message and returns the raw Signature without a VerifyingKey for verification

Never returns an error.

Implements:

func (*Ed25519PrivateKey) SimulationAuthenticator added in v0.6.0

func (key *Ed25519PrivateKey) SimulationAuthenticator() *AccountAuthenticator

SimulationAuthenticator creates a new AccountAuthenticator for simulation purposes

Implements:

func (*Ed25519PrivateKey) ToHex

func (key *Ed25519PrivateKey) ToHex() string

ToHex returns the hex string representation of the Ed25519PrivateKey, with a leading 0x

Implements:

func (*Ed25519PrivateKey) VerifyingKey

func (key *Ed25519PrivateKey) VerifyingKey() VerifyingKey

VerifyingKey returns the Ed25519PublicKey associated with the Ed25519PrivateKey

Implements:

type Ed25519PublicKey

type Ed25519PublicKey struct {
	Inner ed25519.PublicKey // Inner is the actual public key
}

Ed25519PublicKey is a Ed25519PublicKey which can be used to verify signatures

Implements:

func (*Ed25519PublicKey) AuthKey

func (key *Ed25519PublicKey) AuthKey() *AuthenticationKey

AuthKey returns the AuthenticationKey associated with the Ed25519PublicKey for a Ed25519Scheme.

Implements:

func (*Ed25519PublicKey) Bytes

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

Bytes returns the raw bytes of the Ed25519PublicKey

Implements:

func (*Ed25519PublicKey) FromBytes

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

FromBytes sets the Ed25519PublicKey to the given bytes

Returns an error if the bytes length is not ed25519.PublicKeySize.

Implements:

func (*Ed25519PublicKey) FromHex

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

FromHex sets the Ed25519PublicKey to the bytes represented by the hex string, with or without a leading 0x

Errors if the hex string is not valid, or if the bytes length is not ed25519.PublicKeySize.

Implements:

func (*Ed25519PublicKey) MarshalBCS

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

MarshalBCS serializes the Ed25519PublicKey to BCS bytes

Implements:

func (*Ed25519PublicKey) Scheme

func (key *Ed25519PublicKey) Scheme() uint8

Scheme returns the Ed25519Scheme for the Ed25519PublicKey

Implements:

func (*Ed25519PublicKey) ToHex

func (key *Ed25519PublicKey) ToHex() string

ToHex returns the hex string representation of the Ed25519PublicKey with a leading 0x

Implements:

func (*Ed25519PublicKey) UnmarshalBCS

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

UnmarshalBCS deserializes the Ed25519PublicKey from BCS bytes

Sets bcs.Deserializer.Error if the bytes length is not ed25519.PublicKeySize, or if it fails to read the required bytes.

Implements:

func (*Ed25519PublicKey) Verify

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

Verify verifies a message with the public key and Signature

Returns false if the signature is not Ed25519Signature, or if the verification fails.

Implements:

type Ed25519Signature

type Ed25519Signature struct {
	Inner [ed25519.SignatureSize]byte // Inner is the actual signature
}

Ed25519Signature a wrapper for serialization of Ed25519 signatures

Implements:

func (*Ed25519Signature) Bytes

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

Bytes returns the raw bytes of the Ed25519Signature

Implements:

func (*Ed25519Signature) FromBytes

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

FromBytes sets the Ed25519Signature to the given bytes

Returns an error if the bytes length is not ed25519.SignatureSize.

Implements:

func (*Ed25519Signature) FromHex

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

FromHex sets the Ed25519Signature to the bytes represented by the hex string, with or without a leading 0x

Errors if the hex string is not valid, or if the bytes length is not ed25519.SignatureSize.

Implements:

func (*Ed25519Signature) MarshalBCS

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

MarshalBCS serializes the Ed25519Signature to BCS bytes

Implements:

func (*Ed25519Signature) ToHex

func (e *Ed25519Signature) ToHex() string

ToHex returns the hex string representation of the Ed25519Signature, with a leading 0x

Implements:

func (*Ed25519Signature) UnmarshalBCS

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

UnmarshalBCS deserializes the Ed25519Signature from BCS bytes

Sets bcs.Deserializer.Error if it fails to read the required ed25519.SignatureSize bytes.

Implements:

type IndexedAnySignature added in v0.7.0

type IndexedAnySignature struct {
	Index     uint8
	Signature *AnySignature
}

func (*IndexedAnySignature) MarshalBCS added in v0.7.0

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

func (*IndexedAnySignature) UnmarshalBCS added in v0.7.0

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

UnmarshalBCS converts the signature from BCS

Implements:

type MessageSigner

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

	// EmptySignature creates an empty signature for use in simulation
	EmptySignature() Signature

	// VerifyingKey Retrieve the [VerifyingKey] 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. An example is Secp256k1PrivateKey

type MultiEd25519Authenticator

type MultiEd25519Authenticator struct {
	PubKey *MultiEd25519PublicKey
	Sig    *MultiEd25519Signature
}

MultiEd25519Authenticator is an authenticator for a MultiEd25519Signature

Implements:

func (*MultiEd25519Authenticator) MarshalBCS

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

MarshalBCS serializes the authenticator to bytes

Implements:

func (*MultiEd25519Authenticator) PublicKey

func (ea *MultiEd25519Authenticator) PublicKey() PublicKey

PublicKey returns the public key associated with the authenticator

Implements:

func (*MultiEd25519Authenticator) Signature

func (ea *MultiEd25519Authenticator) Signature() Signature

Signature returns the signature associated with the authenticator

Implements:

func (*MultiEd25519Authenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the authenticator from bytes

Returns an error if deserialization fails due to invalid keys or not enough bytes.

Implements:

func (*MultiEd25519Authenticator) Verify

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

Verify verifies the signature against the message

Implements:

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:

func (*MultiEd25519PublicKey) AuthKey

func (key *MultiEd25519PublicKey) AuthKey() *AuthenticationKey

AuthKey converts the public key to an authentication key

Implements:

func (*MultiEd25519PublicKey) Bytes

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

Bytes serializes the public key to bytes

Implements:

func (*MultiEd25519PublicKey) FromBytes

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

FromBytes deserializes the public key from bytes

Returns an error if deserialization fails due to invalid keys.

Implements:

func (*MultiEd25519PublicKey) FromHex

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

FromHex deserializes the public key from a hex string

Returns an error if deserialization fails due to invalid keys.

Implements:

func (*MultiEd25519PublicKey) MarshalBCS

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

MarshalBCS serializes the public key to bytes

Implements:

func (*MultiEd25519PublicKey) Scheme

func (key *MultiEd25519PublicKey) Scheme() uint8

Scheme returns the scheme for the public key

Implements:

func (*MultiEd25519PublicKey) ToHex

func (key *MultiEd25519PublicKey) ToHex() string

ToHex serializes the public key to a hex string

Implements:

func (*MultiEd25519PublicKey) UnmarshalBCS

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

UnmarshalBCS deserializes the public key from bytes

Returns an error if deserialization fails due to invalid keys or not enough bytes.

Implements:

func (*MultiEd25519PublicKey) Verify

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

Verify verifies the signature against the message

This function will return true if the number of verified signatures is greater than or equal to the number of required signatures

Implements:

type MultiEd25519Signature

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

MultiEd25519Signature is a signature for off-chain multi-sig

Implements:

func (*MultiEd25519Signature) Bytes

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

Bytes serializes the signature to bytes

Implements:

func (*MultiEd25519Signature) FromBytes

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

FromBytes deserializes the signature from bytes

Returns an error if deserialization fails due to invalid keys or not enough bytes.

Implements:

func (*MultiEd25519Signature) FromHex

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

FromHex deserializes the signature from a hex string

Returns an error if deserialization fails due to invalid keys.

Implements:

func (*MultiEd25519Signature) MarshalBCS

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

MarshalBCS serializes the signature to bytes

Implements:

func (*MultiEd25519Signature) ToHex

func (e *MultiEd25519Signature) ToHex() string

ToHex serializes the signature to a hex string

Implements:

func (*MultiEd25519Signature) UnmarshalBCS

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

UnmarshalBCS deserializes the signature from bytes

Returns an error if deserialization fails due to invalid keys or not enough bytes.

Implements

type MultiKey

type MultiKey struct {
	PubKeys            []*AnyPublicKey // The public keys of the sub-keys
	SignaturesRequired uint8           // The number of signatures required to pass verification
}

MultiKey is an off-chain multi-sig, where multiple different keys can be used together to create an account

Implements:

func (*MultiKey) AuthKey

func (key *MultiKey) AuthKey() *AuthenticationKey

AuthKey converts the public key to an authentication key

Implements:

func (*MultiKey) Bytes

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

Bytes converts the public key to bytes

Implements:

func (*MultiKey) FromBytes

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

FromBytes converts the public key from bytes

Implements:

func (*MultiKey) FromHex

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

FromHex converts the public key from a hex string

Implements:

func (*MultiKey) MarshalBCS

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

MarshalBCS converts the public key to BCS

Implements:

func (*MultiKey) Scheme

func (key *MultiKey) Scheme() uint8

Scheme returns the scheme for the public key

Implements:

func (*MultiKey) ToHex

func (key *MultiKey) ToHex() string

ToHex converts the public key to a hex string

Implements:

func (*MultiKey) UnmarshalBCS

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

UnmarshalBCS converts the public key from BCS

Implements:

func (*MultiKey) Verify

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

Verify verifies the signature against the message This function will return true if the number of verified signatures is greater than or equal to the number of required signatures

Implements:

type MultiKeyAuthenticator

type MultiKeyAuthenticator struct {
	PubKey *MultiKey          // The public key of the authenticator
	Sig    *MultiKeySignature // The signature of the authenticator
}

MultiKeyAuthenticator is an on-chain authenticator for a MultiKeySignature

Implements:

func (*MultiKeyAuthenticator) MarshalBCS

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

MarshalBCS serializes the authenticator to bytes

Implements:

func (*MultiKeyAuthenticator) PublicKey

func (ea *MultiKeyAuthenticator) PublicKey() PublicKey

PublicKey returns the public key of the authenticator

Implements:

func (*MultiKeyAuthenticator) Signature

func (ea *MultiKeyAuthenticator) Signature() Signature

Signature returns the signature of the authenticator

Implements:

func (*MultiKeyAuthenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the authenticator from bytes

Implements:

func (*MultiKeyAuthenticator) Verify

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

Verify verifies the signature against the message

Implements:

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) Indices added in v0.7.0

func (bm *MultiKeyBitmap) Indices() []uint8

func (*MultiKeyBitmap) MarshalBCS

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

MarshalBCS serializes the bitmap to bytes

Implements:

func (*MultiKeyBitmap) UnmarshalBCS

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

UnmarshalBCS deserializes the bitmap from bytes

Implements:

type MultiKeySignature

type MultiKeySignature struct {
	Signatures []*AnySignature // The signatures of the sub-keys
	Bitmap     MultiKeyBitmap  // The bitmap of the signatures
}

MultiKeySignature is an off-chain multi-sig signature that can be verified by a MultiKey

Implements:

func NewMultiKeySignature added in v0.7.0

func NewMultiKeySignature(signatures []IndexedAnySignature) (*MultiKeySignature, error)

func (*MultiKeySignature) Bytes

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

Bytes converts the signature to bytes

Implements:

func (*MultiKeySignature) FromBytes

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

FromBytes converts the signature from bytes

Implements:

func (*MultiKeySignature) FromHex

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

FromHex converts the signature from a hex string

Implements:

func (*MultiKeySignature) MarshalBCS

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

MarshalBCS converts the signature to BCS

Implements:

func (*MultiKeySignature) ToHex

func (e *MultiKeySignature) ToHex() string

ToHex converts the signature to a hex string

Implements:

func (*MultiKeySignature) UnmarshalBCS

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

UnmarshalBCS converts the signature from BCS

Implements:

type PublicKey

type PublicKey interface {
	VerifyingKey

	// AuthKey gives the [AuthenticationKey] associated with the [PublicKey]
	AuthKey() *AuthenticationKey

	// Scheme The [DeriveScheme] 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 // PubKey is the public key
	Sig    *Secp256k1Signature // Sig is the signature
}

Secp256k1Authenticator is the authenticator for Secp256k1, but it cannot stand on its own and must be used with SingleKeyAuthenticator

Implements:

func (*Secp256k1Authenticator) MarshalBCS

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

MarshalBCS serializes the Secp256k1Authenticator to BCS bytes

Implements:

func (*Secp256k1Authenticator) PublicKey

func (ea *Secp256k1Authenticator) PublicKey() VerifyingKey

PublicKey returns the VerifyingKey for the authenticator

Implements:

func (*Secp256k1Authenticator) Signature

func (ea *Secp256k1Authenticator) Signature() Signature

Signature returns the Signature for the authenticator

Implements:

func (*Secp256k1Authenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the Secp256k1Authenticator from BCS bytes

Implements:

func (*Secp256k1Authenticator) Verify

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

Verify returns true if the authenticator can be cryptographically verified

Implements:

type Secp256k1PrivateKey

type Secp256k1PrivateKey struct {
	Inner *ecdsa.PrivateKey // Inner is the actual private key
}

Secp256k1PrivateKey is a private key that can be used with SingleSigner. It cannot stand on its own.

Implements:

func GenerateSecp256k1Key

func GenerateSecp256k1Key() (*Secp256k1PrivateKey, error)

GenerateSecp256k1Key generates a new Secp256k1PrivateKey

func (*Secp256k1PrivateKey) Bytes

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

Bytes outputs the raw byte representation of the Secp256k1PrivateKey

Implements:

func (*Secp256k1PrivateKey) EmptySignature added in v0.6.0

func (key *Secp256k1PrivateKey) EmptySignature() Signature

EmptySignature creates an empty signature for use in simulation

Implements:

func (*Secp256k1PrivateKey) FromBytes

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

FromBytes populates the Secp256k1PrivateKey from bytes

Returns an error if the bytes length is not Secp256k1PrivateKeyLength

Implements:

func (*Secp256k1PrivateKey) FromHex

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

FromHex populates the Secp256k1PrivateKey from a hex string

Returns an error if the hex string is invalid or is not Secp256k1PrivateKeyLength bytes

Implements:

func (*Secp256k1PrivateKey) SignMessage

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

SignMessage signs a message and returns the raw Signature without a PublicKey for verification

Implements:

func (*Secp256k1PrivateKey) ToHex

func (key *Secp256k1PrivateKey) ToHex() string

ToHex serializes the private key to a hex string

Implements:

func (*Secp256k1PrivateKey) VerifyingKey

func (key *Secp256k1PrivateKey) VerifyingKey() VerifyingKey

VerifyingKey returns the corresponding public key for the private key

Implements:

type Secp256k1PublicKey

type Secp256k1PublicKey struct {
	Inner *ecdsa.PublicKey // Inner is the actual public key
}

Secp256k1PublicKey is the corresponding public key for Secp256k1PrivateKey, it cannot be used on its own

Implements:

func (*Secp256k1PublicKey) Bytes

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

Bytes returns the raw bytes of the Secp256k1PublicKey

Implements:

func (*Secp256k1PublicKey) FromBytes

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

FromBytes sets the Secp256k1PublicKey to the given bytes

Implements:

func (*Secp256k1PublicKey) FromHex

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

FromHex sets the Secp256k1PublicKey to the bytes represented by the hex string, with or without a leading 0x

Implements:

func (*Secp256k1PublicKey) MarshalBCS

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

MarshalBCS serializes the Secp256k1PublicKey to BCS bytes

Implements:

func (*Secp256k1PublicKey) ToHex

func (key *Secp256k1PublicKey) ToHex() string

ToHex returns the hex string representation of the Secp256k1PublicKey, with a leading 0x

Implements:

func (*Secp256k1PublicKey) UnmarshalBCS

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

UnmarshalBCS deserializes the Secp256k1PublicKey from BCS bytes

Implements:

func (*Secp256k1PublicKey) Verify

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

Verify verifies the signature of a message

Returns true if the signature is valid and a Secp256k1Signature, false otherwise

Implements:

type Secp256k1Signature

type Secp256k1Signature struct {
	Inner [Secp256k1SignatureLength]byte // Inner is the actual signature
}

Secp256k1Signature a wrapper for serialization of Secp256k1 signatures

Implements:

func (*Secp256k1Signature) Bytes

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

Bytes returns the raw bytes of the Secp256k1Signature

Implements:

func (*Secp256k1Signature) FromBytes

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

FromBytes sets the Secp256k1Signature to the given bytes

Returns an error if the bytes length is not Secp256k1SignatureLength

Implements: - CryptoMaterial

func (*Secp256k1Signature) FromHex

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

FromHex sets the Secp256k1Signature to the bytes represented by the hex string, with or without a leading 0x

Returns an error if the hex string is invalid or is not Secp256k1SignatureLength bytes

Implements:

func (*Secp256k1Signature) MarshalBCS

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

MarshalBCS serializes the Secp256k1Signature to BCS bytes

Implements:

func (*Secp256k1Signature) ToHex

func (e *Secp256k1Signature) ToHex() string

ToHex returns the hex string representation of the Secp256k1Signature, with a leading 0x

Implements:

func (*Secp256k1Signature) UnmarshalBCS

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

UnmarshalBCS deserializes the Secp256k1Signature from BCS bytes

Implements:

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 [AccountAuthenticator]
	Sign(msg []byte) (authenticator *AccountAuthenticator, err error)

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

	// SimulationAuthenticator creates a new [AccountAuthenticator] for simulation purposes
	SimulationAuthenticator() *AccountAuthenticator

	// AuthKey gives the [AuthenticationKey] associated with the [Signer]
	AuthKey() *AuthenticationKey

	// PubKey Retrieve the [PublicKey] 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:

func (*SingleKeyAuthenticator) MarshalBCS

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

MarshalBCS serializes the authenticator to bytes

Implements:

func (*SingleKeyAuthenticator) PublicKey

func (ea *SingleKeyAuthenticator) PublicKey() PublicKey

PublicKey returns the public key of the authenticator

Implements:

func (*SingleKeyAuthenticator) Signature

func (ea *SingleKeyAuthenticator) Signature() Signature

Signature returns the signature of the authenticator

Implements:

func (*SingleKeyAuthenticator) UnmarshalBCS

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

UnmarshalBCS deserializes the authenticator from bytes

Implements:

func (*SingleKeyAuthenticator) Verify

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

Verify verifies the signature against the message

Implements:

type SingleSigner

type SingleSigner struct {
	Signer MessageSigner // Signer is the actual signer or private key
}

SingleSigner is a wrapper around different types of MessageSigners to allow for many types of keys

Implements:

func NewSingleSigner

func NewSingleSigner(input MessageSigner) *SingleSigner

NewSingleSigner creates a new SingleSigner with the given MessageSigner

func (*SingleSigner) AuthKey

func (key *SingleSigner) AuthKey() *AuthenticationKey

AuthKey gives the AuthenticationKey associated with the Signer

Implements:

func (*SingleSigner) EmptySignature added in v0.6.0

func (key *SingleSigner) EmptySignature() *AnySignature

func (*SingleSigner) PubKey

func (key *SingleSigner) PubKey() PublicKey

PubKey Retrieve the PublicKey for Signature verification

Implements:

func (*SingleSigner) Sign

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

Sign signs a transaction and returns an associated AccountAuthenticator

Implements:

func (*SingleSigner) SignMessage

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

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

func (*SingleSigner) SignatureVariant added in v0.6.0

func (key *SingleSigner) SignatureVariant() AnySignatureVariant

func (*SingleSigner) SimulationAuthenticator added in v0.6.0

func (key *SingleSigner) SimulationAuthenticator() *AccountAuthenticator

SimulationAuthenticator creates a new AccountAuthenticator for simulation purposes

Implements:

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 PublicKey for authentication on Aptos. An example is Secp256k1PublicKey. All [PublicKey]s are also VerifyingKeys.

Jump to

Keyboard shortcuts

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