identity

package
v0.0.0-...-33f4671 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: GPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AppTopicIdentityUnlock  = "identity-unlocked"
	AppTopicIdentityCreated = "identity-created"
)

Identity events

View Source
const AppTopicResidentCountry = "resident-country"

AppTopicResidentCountry resident country event topic

Variables

View Source
var MockDecryptFunc = func(keyjson []byte, auth string) (*ethKs.Key, error) {
	pk, err := crypto.HexToECDSA(common.Bytes2Hex(keyjson))
	if err != nil {
		return nil, err
	}
	return &ethKs.Key{
		PrivateKey: pk,
	}, nil
}

MockDecryptFunc represents the mock decrypt func

View Source
var MockKeys = map[common.Address]MockKey{
	common.HexToAddress("53a835143c0ef3bbcbfa796d7eb738ca7dd28f68"): {
		PkHex: "6f88637b68ee88816e73f663aef709d7009836c98ae91ef31e3dfac7be3a1657",
		Pass:  "",
	},
}

MockKeys represents the mocked keys

Functions

func NewExtractor

func NewExtractor() *extractor

NewExtractor constructs Extractor instance

func NewIdentityManager

func NewIdentityManager(keystore keystore, eventBus eventbus.EventBus, residentCountry *ResidentCountry) *identityManager

NewIdentityManager creates and returns new identityManager

func NewIdentityManagerFake

func NewIdentityManagerFake(existingIdentities []Identity, newIdentity Identity) *idmFake

NewIdentityManagerFake creates fake identity manager for testing purposes TODO each caller should use it's own mocked manager part instead of global one

func NewMockKeystore

func NewMockKeystore() *mockKeystore

NewMockKeystore returns empty mock keystore

func NewMockKeystoreWith

func NewMockKeystoreWith(keys map[common.Address]MockKey) *mockKeystore

NewMockKeystoreWith returns a new mock keystore with specified keys

func NewVerifierIdentity

func NewVerifierIdentity(peerID Identity) *verifierIdentity

NewVerifierIdentity constructs Verifier which:

  • checks signature's sanity
  • checks if message was unchanged by middleman
  • checks if message is from exact identity

func NewVerifierSigned

func NewVerifierSigned() *verifierSigned

NewVerifierSigned constructs Verifier which:

  • checks signature's sanity
  • checks if message was unchanged by middleman

Types

type AppEventIdentityUnlock

type AppEventIdentityUnlock struct {
	ChainID int64
	ID      Identity
}

AppEventIdentityUnlock represents the payload that is sent on identity unlock.

type Exporter

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

Exporter exposes a way to export private keys.

func NewExporter

func NewExporter(ks moverKeystore) *Exporter

NewExporter returns a new exporter object.

func (*Exporter) Export

func (e *Exporter) Export(address, currPass, newPass string) ([]byte, error)

Export exports a given identity and returns it as json blob.

type Extractor

type Extractor interface {
	Extract(message []byte, signature Signature) (Identity, error)
}

Extractor is able to message signer's identity

type Identity

type Identity struct {
	// TODO Encoding should be in transport layer
	Address string `json:"address"`
}

Identity represents unique user network identity

func FromAddress

func FromAddress(address string) Identity

FromAddress converts address to identity

func (Identity) ToCommonAddress

func (i Identity) ToCommonAddress() common.Address

ToCommonAddress returns the common address representation for identity

type IdentityCache

type IdentityCache struct {
	File string
}

IdentityCache saves identity to file

func (*IdentityCache) GetIdentity

func (ic *IdentityCache) GetIdentity() (identity Identity, err error)

GetIdentity retrieves identity from cache

func (*IdentityCache) StoreIdentity

func (ic *IdentityCache) StoreIdentity(identity Identity) error

StoreIdentity stores identity to cache

type IdentityCacheInterface

type IdentityCacheInterface interface {
	GetIdentity() (identity Identity, err error)
	StoreIdentity(identity Identity) error
}

IdentityCacheInterface allows caching single identity

func NewIdentityCache

func NewIdentityCache(dir string, jsonFile string) IdentityCacheInterface

NewIdentityCache creates and returns identityCache

func NewIdentityCacheFake

func NewIdentityCacheFake() IdentityCacheInterface

NewIdentityCacheFake creates and returns fake identity cache

type Importer

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

Importer exposes a way to import an private keys.

func NewImporter

func NewImporter(ks moverKeystore, events eventbus.EventBus, signer SignerFactory) *Importer

NewImporter returns a new importer object.

func (*Importer) Import

func (i *Importer) Import(blob []byte, currPass, newPass string) (Identity, error)

Import imports a given blob as a new identity. It will return an error if that identity was never registered.

type Keystore

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

Keystore handles everything that's related to eth accounts.

func NewKeystoreFilesystem

func NewKeystoreFilesystem(directory string, ks ethKeystore) *Keystore

NewKeystoreFilesystem create new keystore, which keeps keys in filesystem.

func (*Keystore) Decrypt

func (ks *Keystore) Decrypt(addr common.Address, encrypted []byte) ([]byte, error)

Decrypt takes a derived key for the given address and decrypts the encrypted message.

func (*Keystore) Encrypt

func (ks *Keystore) Encrypt(addr common.Address, plaintext []byte) ([]byte, error)

Encrypt takes a derived key for the given address and encrypts the plaintext.

func (*Keystore) Lock

func (ks *Keystore) Lock(addr common.Address) error

Lock removes the private key with the given address from memory.

func (*Keystore) SignHash

func (ks *Keystore) SignHash(a accounts.Account, hash []byte) ([]byte, error)

SignHash calculates a ECDSA signature for the given hash. The produced signature is in the [R || S || V] format where V is 0 or 1.

func (*Keystore) TimedUnlock

func (ks *Keystore) TimedUnlock(a accounts.Account, passphrase string, timeout time.Duration) error

TimedUnlock unlocks the given account with the passphrase. The account stays unlocked for the duration of timeout. A timeout of 0 unlocks the account until the program exits. The account must match a unique key file.

If the account address is already unlocked for a duration, TimedUnlock extends or shortens the active unlock timeout. If the address was previously unlocked indefinitely the timeout is not altered.

func (*Keystore) Unlock

func (ks *Keystore) Unlock(a accounts.Account, passphrase string) error

Unlock unlocks the given account indefinitely.

type Manager

type Manager interface {
	CreateNewIdentity(passphrase string) (Identity, error)
	GetIdentities() []Identity
	GetIdentity(address string) (Identity, error)
	HasIdentity(address string) bool
	Unlock(chainID int64, address string, passphrase string) error
	IsUnlocked(address string) bool
	GetUnlockedIdentity() (Identity, bool)
}

Manager interface exposes identity management methods TODO this interface must decay into caller specific smaller interfaces

type MockKey

type MockKey struct {
	PkHex string
	Pass  string
	// contains filtered or unexported fields
}

MockKey represents a mocked key

type Mover

type Mover struct {
	*Exporter
	*Importer
}

Mover is wrapper on both the Exporter and Importer and can be used to manipulate private keys in to either direction.

func NewMover

func NewMover(ks moverKeystore, events eventbus.EventBus, signer SignerFactory) *Mover

NewMover returns a new mover object.

type ResidentCountry

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

ResidentCountry for saving and loading resident country resident country is used by legal to pay VAT

func NewResidentCountry

func NewResidentCountry(eventBus eventbus.EventBus, locationResolver locationProvider) *ResidentCountry

NewResidentCountry constructor

func (*ResidentCountry) Get

func (rc *ResidentCountry) Get() string

Get get stored resident country

func (*ResidentCountry) Save

func (rc *ResidentCountry) Save(identity, countryCode string) error

Save country code and fire AppTopicResidentCountry

type ResidentCountryEvent

type ResidentCountryEvent struct {
	ID      string
	Country string
}

ResidentCountryEvent represent actual resident country changed event

type Signature

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

Signature structure

func SignatureBase64

func SignatureBase64(signature string) Signature

SignatureBase64 decodes base64 string signature into Signature

func SignatureBytes

func SignatureBytes(signatureBytes []byte) Signature

SignatureBytes constructs Signature structure instance from bytes

func SignatureHex

func SignatureHex(signature string) Signature

SignatureHex returns Signature struct from hex string

func (*Signature) Base64

func (signature *Signature) Base64() string

Base64 encodes signature into Base64 format

func (*Signature) Bytes

func (signature *Signature) Bytes() []byte

Bytes returns signature in raw bytes format

func (Signature) EqualsTo

func (signature Signature) EqualsTo(other Signature) bool

EqualsTo compares current signature with a given one

type Signer

type Signer interface {
	Sign(message []byte) (Signature, error)
}

Signer interface signifies an ability to sign a message

func NewSigner

func NewSigner(keystore keystore, identity Identity) Signer

NewSigner returns new instance of Signer

type SignerFactory

type SignerFactory func(id Identity) Signer

SignerFactory callback returning Signer

type SignerFake

type SignerFake struct {
	ErrorMock error
}

SignerFake represents fake signer for testing purposes TODO each caller (or use case) must use its own mocked signer in testing

func (*SignerFake) Sign

func (signer *SignerFake) Sign(message []byte) (Signature, error)

Sign signs provided slice of bytes and returns Signature result or error

type Verifier

type Verifier interface {
	Verify(message []byte, signature Signature) (bool, Identity)
}

Verifier checks message's sanity

type VerifierFactory

type VerifierFactory func(id Identity) Verifier

VerifierFactory callback returning Verifier

type VerifierFake

type VerifierFake struct{}

VerifierFake represents fake signature verifier useful for testing TODO each caller must use its own mocked verifier instead of global one

func (*VerifierFake) Verify

func (verifier *VerifierFake) Verify(message []byte, signature Signature) (bool, Identity)

Verify given message and signature by returning true on success

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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