|
|
|
@ -37,15 +37,8 @@ func DefaultIdentity() string { |
|
|
|
|
return os.ExpandEnv("$HOME/.config/salty/$USER.key") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DefaultEndpoint returns a default inbox file (if one exists) otherwise
|
|
|
|
|
// returns an empty string
|
|
|
|
|
func DefaultEndpoint() string { |
|
|
|
|
return os.ExpandEnv("https://msgbus.mills.io/$USER") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CreateIdentity ...
|
|
|
|
|
func CreateIdentity(options ...IdentityOption) (*Identity, error) { |
|
|
|
|
|
|
|
|
|
ident := &Identity{} |
|
|
|
|
for _, option := range options { |
|
|
|
|
option(ident) |
|
|
|
@ -57,7 +50,8 @@ func CreateIdentity(options ...IdentityOption) (*Identity, error) { |
|
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{} |
|
|
|
|
|
|
|
|
|
salty.GenerateKeys(buf) |
|
|
|
|
key, _ := salty.GenerateKeys(buf) |
|
|
|
|
ident.key = key |
|
|
|
|
|
|
|
|
|
buf.Write([]byte(fmt.Sprintf("# user: %s\n", ident.addr.String()))) |
|
|
|
|
|
|
|
|
@ -92,7 +86,6 @@ func CreateIdentity(options ...IdentityOption) (*Identity, error) { |
|
|
|
|
|
|
|
|
|
// GetIdentity ...
|
|
|
|
|
func GetIdentity(options ...IdentityOption) (*Identity, error) { |
|
|
|
|
|
|
|
|
|
ident := &Identity{} |
|
|
|
|
for _, option := range options { |
|
|
|
|
option(ident) |
|
|
|
@ -134,10 +127,13 @@ func GetIdentity(options ...IdentityOption) (*Identity, error) { |
|
|
|
|
type Identity struct { |
|
|
|
|
// path where identity is read or written to
|
|
|
|
|
path string |
|
|
|
|
|
|
|
|
|
// contents where identity is read from or stored
|
|
|
|
|
contents []byte |
|
|
|
|
|
|
|
|
|
// key is the identity key
|
|
|
|
|
key *keys.EdX25519Key |
|
|
|
|
|
|
|
|
|
// addr is the user / endpoint
|
|
|
|
|
addr *Addr |
|
|
|
|
} |
|
|
|
@ -164,17 +160,17 @@ func (i *Identity) Addr() *Addr { |
|
|
|
|
// IdentityOption represents functional options for various identity operations
|
|
|
|
|
type IdentityOption func(*Identity) |
|
|
|
|
|
|
|
|
|
// IdentityAddr sets the identity Addr option
|
|
|
|
|
func IdentityAddr(addr *Addr) IdentityOption { |
|
|
|
|
// WithIdentityAddr sets the identity Addr option
|
|
|
|
|
func WithIdentityAddr(addr *Addr) IdentityOption { |
|
|
|
|
return func(i *Identity) { i.addr = addr } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// IdentityPath indicates that an identity should be read / written from a file path
|
|
|
|
|
func IdentityPath(path string) IdentityOption { |
|
|
|
|
// WithIdentityPath indicates that an identity should be read / written from a file path
|
|
|
|
|
func WithIdentityPath(path string) IdentityOption { |
|
|
|
|
return func(i *Identity) { i.path = path } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// IdentityContents indicates that the identity should be read from a byte array
|
|
|
|
|
func IdentityContents(contents []byte) IdentityOption { |
|
|
|
|
// WithIdentityBytes indicates that the identity should be read from a byte array
|
|
|
|
|
func WithIdentityBytes(contents []byte) IdentityOption { |
|
|
|
|
return func(i *Identity) { i.contents = contents } |
|
|
|
|
} |
|
|
|
|