accounts

package
v0.0.0-...-da72ffe Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

pkg/accounts/ethereum.go

pkg/accounts/rbac.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeAccountID

func ComputeAccountID(signerType types.SignerType, pubKeyBytes []byte) string

ComputeAccountID computes the account ID using SignerType and public key bytes.

func PublicKeyToAddress

func PublicKeyToAddress(pubKeyBytes []byte) (types.Address, error)

PublicKeyToAddress derives the Address from the public key bytes.

Types

type Account

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

Account represents a Decentralized Identifier with associated cryptographic keys and permissions.

func NewAccount

func NewAccount(
	logger logger.Logger,
	peerID peer.ID,
	peerSk libp2pCrypto.PrivKey,
	peerPk libp2pCrypto.PubKey,
	signerType types.SignerType,
	name, comment string,
	roles []types.Role,
	extraPermissions map[types.Role][]types.Permission,
	rbacMgr *rbac.Manager,
) (*Account, error)

NewAccount initializes a new Account with all the cryptographic keys and metadata.

func NewConsensusAccount

func NewConsensusAccount(logger logger.Logger, peerId peer.ID, address types.Address, pubKey libp2pCrypto.PubKey, roles []types.Role) (*Account, error)

NewConsensusAccount initializes Account used by the validators. TODO: This needs to be extended with roles and many more things but for now it's this

func (*Account) Address

func (a *Account) Address() types.Address

Address returns the derived address from the MasterPublicKey.

func (*Account) AssignRole

func (a *Account) AssignRole(role types.Role, permissions ...types.Permission) error

AssignRole assigns a new role to the account.

func (*Account) Authorize

func (a *Account) Authorize(permission types.Permission) error

Authorize ensures the account has the required permission.

func (*Account) Comment

func (a *Account) Comment() string

Comment returns the optional comment or description of the account.

func (*Account) ExtraPermissions

func (a *Account) ExtraPermissions() map[types.Role][]types.Permission

ExtraPermissions returns the additional permissions associated with each role.

func (*Account) HasPermission

func (a *Account) HasPermission(permission types.Permission) bool

HasPermission checks if the account has the specified permission.

func (*Account) ID

func (a *Account) ID() string

ID returns the unique identifier of the account.

func (*Account) MarshalPublicKey

func (a *Account) MarshalPublicKey() ([]byte, error)

func (*Account) MasterKeyToECDSA

func (a *Account) MasterKeyToECDSA() (*ecdsa.PrivateKey, error)

func (*Account) MasterPrivateKey

func (a *Account) MasterPrivateKey() libp2pCrypto.PrivKey

MasterPrivateKey returns the master private key associated with the account.

func (*Account) MasterPublicKey

func (a *Account) MasterPublicKey() libp2pCrypto.PubKey

MasterPublicKey returns the master public key associated with the account.

func (*Account) Name

func (a *Account) Name() string

Name returns the name of the account.

func (*Account) PeerID

func (a *Account) PeerID() peer.ID

PeerID returns the associated libp2p PeerID.

func (*Account) RemoveRole

func (a *Account) RemoveRole(role types.Role) error

RemoveRole removes a role from the account.

func (*Account) Roles

func (a *Account) Roles() []types.Role

Roles returns the list of roles assigned to the account.

func (*Account) Sign

func (a *Account) Sign(data []byte) ([]byte, error)

Sign signs the provided data using the account's master private key

func (*Account) SupportedProtocols

func (a *Account) SupportedProtocols() []types.ProtocolType

TODO: Not even sure how to do this... And is this even how it should be done... Perhaps based on node type and configuration instead of anything else...

func (*Account) SupportedTransports

func (a *Account) SupportedTransports() []types.TransportType

TODO: Not even sure how to do this... And is this even how it should be done... Perhaps based on node type and configuration instead of anything else...

func (*Account) Verify

func (a *Account) Verify(data []byte, signature []byte) (bool, error)

Verify checks if the signature is valid for the given data using the account's master public key

type Store

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

Store manages the persistence of Accounts using YAML files.

func NewStore

func NewStore(cfg config.Identity, logger logger.Logger, rbacMgr *rbac.Manager) (*Store, error)

NewStore initializes a new Store with the identity configuration.

func (*Store) Create

func (s *Store) Create(name, comment string, signer types.SignerType, persist bool, roles ...types.Role) (*Account, error)

Create generates a new Account and stores it as a YAML file.

func (*Store) Delete

func (s *Store) Delete(peerID libp2pPeer.ID) error

Delete removes an Account from the storage by deleting its corresponding YAML file and removing it from memory.

func (*Store) GetByAddress

func (s *Store) GetByAddress(addr types.Address) (*Account, error)

GetByAddress returns an Account by its Address if it exists in memory.

func (*Store) GetByName

func (s *Store) GetByName(name string) (*Account, error)

GetByName returns an Account by its name if it exists in memory.

func (*Store) GetByPeerID

func (s *Store) GetByPeerID(peerID libp2pPeer.ID) (*Account, error)

GetByPeerID returns an Account by its peer.ID if it exists in memory.

func (*Store) GetByRole

func (s *Store) GetByRole(role types.Role) (*Account, error)

GetByRole returns an Account by its role if it exists in memory.

func (*Store) List

func (s *Store) List() ([]*Account, error)

List returns a list of all Accounts stored in memory.

func (*Store) Load

func (s *Store) Load() error

Load reads all Accounts from individual YAML files and reconstructs them in the Store's keys map.

func (*Store) Save

func (s *Store) Save(account *Account) error

Save persists an Account to a YAML file in the configured base path.

Jump to

Keyboard shortcuts

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