accountkeymetadata

package
v0.43.1-rc.1.access-me... Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SentinelFastDigest64 uint64 = 0 // don't change this value (instead, declare new constant with new value if needed)

SentinelFastDigest64 is the sentinel digest used for 64-bit fast hash collision handling. SentinelFastDigest64 is stored in key metadata's digest list as a placeholder.

Variables

This section is empty.

Functions

func FindDuplicateKey

func FindDuplicateKey(
	keyMetadata *KeyMetadataAppender,
	encodedKey []byte,
	getKeyDigest func([]byte) uint64,
	getStoredKey func(uint32) ([]byte, error),
) (digest uint64, found bool, duplicateStoredKeyIndex uint32, _ error)

FindDuplicateKey returns true with duplicate key index if duplicate key of the given key is found. However, detection rate is intentionally not 100% in order to limit the number of digests we store on chain. If a hash collision happens with given digest, this function returns SentinelFastDigest64 digest and duplicate key not found. Specifically, a duplicate key is found when these conditions are met: - computed digest isn't the predefined sentinel digest (0), - computed digest matches one of the stored digests in key metadata, and - given encodedKey also matches the stored key with the same digest.

func GetKeyMetadata

func GetKeyMetadata(b []byte, keyIndex uint32, deduplicated bool) (
	weight uint16,
	revoked bool,
	storedKeyIndex uint32,
	err error,
)

GetKeyMetadata returns weight, revoked status, and stored key index for given account public key index.

func GetPublicKeyDigest

func GetPublicKeyDigest(owner flow.Address, encodedPublicKey []byte) uint64

func GetRevokedStatus

func GetRevokedStatus(b []byte, keyIndex uint32) (bool, error)

GetRevokedStatus returns revoked status for account public key at the key index.

func SetRevokedStatus

func SetRevokedStatus(b []byte, keyIndex uint32) ([]byte, error)

SetRevokedStatus revokes key and returns encoded key metadata. NOTE: b may be modified.

Types

type KeyMetadataAppender

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

func NewKeyMetadataAppender

func NewKeyMetadataAppender(key0Digest uint64, maxStoredDigests uint32) *KeyMetadataAppender

func NewKeyMetadataAppenderFromBytes

func NewKeyMetadataAppenderFromBytes(b []byte, deduplicated bool, maxStoredDigests uint32) (*KeyMetadataAppender, error)

NewKeyMetadataAppenderFromBytes returns KeyMetadataAppender used to append new key metadata. NOTE: b can be modified.

func (*KeyMetadataAppender) AppendDuplicateKeyMetadata

func (m *KeyMetadataAppender) AppendDuplicateKeyMetadata(
	keyIndex uint32,
	duplicateStoredKeyIndex uint32,
	revoked bool,
	weight uint16,
) (err error)

AppendDuplicateKeyMetadata appends duplicate key metadata.

func (*KeyMetadataAppender) AppendUniqueKeyMetadata

func (m *KeyMetadataAppender) AppendUniqueKeyMetadata(
	revoked bool,
	weight uint16,
	digest uint64,
) (storedKeyIndex uint32, err error)

AppendUniqueKeyMetadata appends unique key metadata.

func (*KeyMetadataAppender) ToBytes

func (m *KeyMetadataAppender) ToBytes() ([]byte, bool)

With deduplicated flag, account key metadata is encoded as: - length prefixed list of account public key weight and revoked status starting from key index 1 - startKeyIndex (4 bytes) + length prefixed list of account public key index mappings to stored key index - startStoredKeyIndex (4 bytes) + length prefixed list of last N stored key digests

Without deduplicated flag, account key metadata is encoded as: - length prefixed list of account public key weight and revoked status starting from key index 1 - startStoredKeyIndex (4 bytes) + length prefixed list of last N stored key digests

type MappingGroup

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

func NewMappingGroup

func NewMappingGroup(runLength uint16, storedKeyIndex uint32, consecutive bool) *MappingGroup

func (*MappingGroup) Encode

func (g *MappingGroup) Encode() []byte

func (*MappingGroup) TryMerge

func (g *MappingGroup) TryMerge(storedKeyIndex uint32) bool

TryMerge returns true if the given storedKeyIndex is merged into g. The given storedKeyIndex is merged into regular group g if g's runLength is less than maxRunLengthInMappingGroup and either g's storedKeyIndex is the same as the given storedKeyIndex or g's runLength is 1 and g's storedKeyIndex + 1 is the same as the given storedKeyIndex. The given storedKeyIndex is merged into consecutive group g if g's runLength is less than maxRunLengthInMappingGroup and g's storedKeyIndex + g's runLength the same as the given storedKeyIndex.

type MappingGroups

type MappingGroups []*MappingGroup

func (MappingGroups) Encode

func (groups MappingGroups) Encode() []byte

Jump to

Keyboard shortcuts

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