Documentation ¶
Index ¶
- Constants
- Variables
- func NewExtractor() *extractor
- func NewIdentityManager(keystore keystore, eventBus eventbus.EventBus, ...) *identityManager
- func NewIdentityManagerFake(existingIdentities []Identity, newIdentity Identity) *idmFake
- func NewMockKeystore() *mockKeystore
- func NewMockKeystoreWith(keys map[common.Address]MockKey) *mockKeystore
- func NewVerifierIdentity(peerID Identity) *verifierIdentity
- func NewVerifierSigned() *verifierSigned
- type AppEventIdentityUnlock
- type Exporter
- type Extractor
- type Identity
- type IdentityCache
- type IdentityCacheInterface
- type Importer
- type Keystore
- func (ks *Keystore) Decrypt(addr common.Address, encrypted []byte) ([]byte, error)
- func (ks *Keystore) Encrypt(addr common.Address, plaintext []byte) ([]byte, error)
- func (ks *Keystore) Lock(addr common.Address) error
- func (ks *Keystore) SignHash(a accounts.Account, hash []byte) ([]byte, error)
- func (ks *Keystore) TimedUnlock(a accounts.Account, passphrase string, timeout time.Duration) error
- func (ks *Keystore) Unlock(a accounts.Account, passphrase string) error
- type Manager
- type MockKey
- type Mover
- type ResidentCountry
- type ResidentCountryEvent
- type Signature
- type Signer
- type SignerFactory
- type SignerFake
- type Verifier
- type VerifierFactory
- type VerifierFake
Constants ¶
const ( AppTopicIdentityUnlock = "identity-unlocked" AppTopicIdentityCreated = "identity-created" )
Identity events
const AppTopicResidentCountry = "resident-country"
AppTopicResidentCountry resident country event topic
Variables ¶
var MockDecryptFunc = func(keyjson []byte, auth string) (*ethKs.Key, error) { pk, err := crypto.HexToECDSA(common.Bytes2Hex(keyjson)) if err != nil { return nil, err } return ðKs.Key{ PrivateKey: pk, }, nil }
MockDecryptFunc represents the mock decrypt func
var MockKeys = map[common.Address]MockKey{ common.HexToAddress("53a835143c0ef3bbcbfa796d7eb738ca7dd28f68"): { PkHex: "6f88637b68ee88816e73f663aef709d7009836c98ae91ef31e3dfac7be3a1657", Pass: "", }, }
MockKeys represents the mocked keys
Functions ¶
func NewIdentityManager ¶
func NewIdentityManager(keystore keystore, eventBus eventbus.EventBus, residentCountry *ResidentCountry) *identityManager
NewIdentityManager creates and returns new identityManager
func NewIdentityManagerFake ¶
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 ¶
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 ¶
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.
type Identity ¶
type Identity struct { // TODO Encoding should be in transport layer Address string `json:"address"` }
Identity represents unique user network identity
func FromAddress ¶
FromAddress converts address to identity
func (Identity) ToCommonAddress ¶
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.
type Keystore ¶
type Keystore struct {
// contains filtered or unexported fields
}
Keystore handles everything that's related to eth accounts.
func NewKeystoreFilesystem ¶
NewKeystoreFilesystem create new keystore, which keeps keys in filesystem.
func (*Keystore) Decrypt ¶
Decrypt takes a derived key for the given address and decrypts the encrypted message.
func (*Keystore) Encrypt ¶
Encrypt takes a derived key for the given address and encrypts the plaintext.
func (*Keystore) SignHash ¶
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 ¶
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.
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 Mover ¶
Mover is wrapper on both the Exporter and Importer and can be used to manipulate private keys in to either direction.
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 ¶
ResidentCountryEvent represent actual resident country changed event
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature structure
func SignatureBase64 ¶
SignatureBase64 decodes base64 string signature into Signature
func SignatureBytes ¶
SignatureBytes constructs Signature structure instance from bytes
func SignatureHex ¶
SignatureHex returns Signature struct from hex string
type SignerFactory ¶
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
type VerifierFactory ¶
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