identity

package
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IndexSchemaVersion           = 3
	IndexFileName                = "index.json"
	LegacyBackupDirName          = ".legacy-backup"
	IdentityFileName             = "identity.json"
	AuthFileName                 = "auth.json"
	DIDDocumentFileName          = "did_document.json"
	Key1PrivateFileName          = "key-1-private.pem"
	Key1PublicFileName           = "key-1-public.pem"
	E2EESigningPrivateFileName   = "e2ee-signing-private.pem"
	E2EEAgreementPrivateFileName = "e2ee-agreement-private.pem"
	E2EEStateFileName            = "e2ee-state.json"
	LegacyE2EEPrefix             = "e2ee_"
	LegacyLayoutHint             = "Legacy credential layout detected. Import it before relying on the v2 identity store."
	DefaultEmailVerificationSecs = 300
	DefaultEmailPollIntervalSecs = 5
)

Variables

View Source
var (
	ErrIdentityNotFound         = errors.New("identity not found")
	ErrIdentityConflict         = errors.New("identity conflict")
	ErrNoDefaultIdentity        = errors.New("no default identity")
	ErrLegacyNotFound           = errors.New("legacy identity not found")
	ErrInvalidInput             = errors.New("invalid input")
	ErrAuthRequired             = errors.New("authentication required")
	ErrUserRegistrationRequired = errors.New("registered handle user is required")
)

Functions

func BuildAgentANPMessageService

func BuildAgentANPMessageService(serviceEndpoint string, serviceDID string) (map[string]any, error)

func CompleteBareHandle

func CompleteBareHandle(target string, didDomain string) string

CompleteBareHandle expands bare and wba://bare handles to a canonical full handle. Explicit full handles and DID values pass through with their original trimmed spelling.

func DefaultANPServiceDID

func DefaultANPServiceDID(hostname string) string

func DefaultANPServiceEndpoint

func DefaultANPServiceEndpoint(hostname string) string

func EnsureKey1PrivatePEMCompatible

func EnsureKey1PrivatePEMCompatible(path string) error

EnsureKey1PrivatePEMCompatible rewrites legacy ANP/private-key PEM encodings into the standard PKCS#8 PEM accepted by ANP SDK 0.8.5+.

func HandlePathPrefixFromDID

func HandlePathPrefixFromDID(did string) (string, []string, error)

func IsE1DID

func IsE1DID(did string) bool

func IsK1DID

func IsK1DID(did string) bool

func PreviewDefaultIdentityName

func PreviewDefaultIdentityName(requested string, existing []IdentitySummary, fallback string) string

func PreviewNamedIdentity

func PreviewNamedIdentity(requested string, existing []IdentitySummary, fallback string) string

func PublicData

func PublicData(data map[string]any) map[string]any

PublicData returns a sanitized copy of identity-domain command output. Internal linkage fields such as user_id must not be exposed through the public CLI contract.

func PublicValue

func PublicValue(value any) any

PublicValue returns a sanitized copy of any public CLI payload. Internal linkage fields such as user_id must not be exposed through the public CLI contract.

func UserRegistrationError

func UserRegistrationError(identityName string, state UserState) error

func ValidateANPServiceDID

func ValidateANPServiceDID(serviceDID string) error

func ValidateANPServiceEndpoint

func ValidateANPServiceEndpoint(serviceEndpoint string) error

Types

type BindParams

type BindParams struct {
	Phone               string
	Email               string
	OTP                 string
	Wait                bool
	VerificationTimeout int
	PollIntervalSeconds float64
}

type CommandResult

type CommandResult struct {
	Data     map[string]any
	Summary  string
	Warnings []string
}

type GenerateOptions

type GenerateOptions struct {
	Hostname           string
	PathPrefix         []string
	ProofDomain        string
	ANPServiceEndpoint string
	ANPServiceDID      string
}

type GeneratedIdentity

type GeneratedIdentity struct {
	DID                     string
	UniqueID                string
	DIDDocument             map[string]any
	Key1PrivatePEM          string
	Key1PublicPEM           string
	E2EESigningPrivatePEM   string
	E2EEAgreementPrivatePEM string
}

func GenerateIdentity

func GenerateIdentity(options GenerateOptions) (*GeneratedIdentity, error)

type HandleLookupResult

type HandleLookupResult struct {
	Handle     string `json:"handle"`
	DID        string `json:"did"`
	Domain     string `json:"domain"`
	FullHandle string `json:"full_handle"`
	Status     string `json:"status"`
}

type IdentitySummary

type IdentitySummary struct {
	IdentityName            string    `json:"identity_name"`
	DID                     string    `json:"did"`
	UniqueID                string    `json:"unique_id"`
	UserID                  string    `json:"user_id,omitempty"`
	DisplayName             string    `json:"display_name,omitempty"`
	Handle                  string    `json:"handle,omitempty"`
	FullHandle              string    `json:"full_handle,omitempty"`
	CreatedAt               string    `json:"created_at,omitempty"`
	DirName                 string    `json:"dir_name"`
	IsDefault               bool      `json:"is_default"`
	HasJWT                  bool      `json:"has_jwt"`
	HasDIDDocument          bool      `json:"has_did_document"`
	HasKey1Private          bool      `json:"has_key1_private"`
	HasKey1Public           bool      `json:"has_key1_public"`
	HasE2EESigningPrivate   bool      `json:"has_e2ee_signing_private"`
	HasE2EEAgreementPrivate bool      `json:"has_e2ee_agreement_private"`
	UserState               UserState `json:"user_state"`
}

type ImportResult

type ImportResult struct {
	Imported []IdentitySummary `json:"imported,omitempty"`
	Skipped  []string          `json:"skipped,omitempty"`
}

type IndexEntry

type IndexEntry struct {
	CredentialName string `json:"credential_name"`
	DirName        string `json:"dir_name"`
	DID            string `json:"did"`
	UniqueID       string `json:"unique_id"`
	UserID         string `json:"user_id,omitempty"`
	Name           string `json:"name,omitempty"`
	Handle         string `json:"handle,omitempty"`
	FullHandle     string `json:"full_handle,omitempty"`
	CreatedAt      string `json:"created_at,omitempty"`
	IsDefault      bool   `json:"is_default,omitempty"`
}

type IndexPayload

type IndexPayload struct {
	SchemaVersion         int                   `json:"schema_version"`
	DefaultCredentialName string                `json:"default_credential_name,omitempty"`
	Credentials           map[string]IndexEntry `json:"credentials"`
}

type LegacyFlatIdentity

type LegacyFlatIdentity struct {
	CredentialName string `json:"credential_name"`
	Path           string `json:"path"`
	DID            string `json:"did"`
	UniqueID       string `json:"unique_id"`
	Handle         string `json:"handle,omitempty"`
}

type LegacyScan

type LegacyScan struct {
	RootDir           string                `json:"root_dir"`
	IndexedLayout     bool                  `json:"indexed_layout"`
	IndexedEntries    map[string]IndexEntry `json:"indexed_entries,omitempty"`
	LegacyCredentials []LegacyFlatIdentity  `json:"legacy_credentials,omitempty"`
	InvalidJSONFiles  []map[string]string   `json:"invalid_json_files,omitempty"`
	OrphanE2EEFiles   []map[string]string   `json:"orphan_e2ee_files,omitempty"`
	HasLegacy         bool                  `json:"has_legacy"`
	Hint              string                `json:"hint,omitempty"`
}

type Manager

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

func NewManager

func NewManager(paths appconfig.Paths) *Manager

func (*Manager) BackupIdentitiesForHandleRecovery

func (m *Manager) BackupIdentitiesForHandleRecovery(handle string, candidates []IdentitySummary, plannedFinalName string, plannedTempName string, activeBefore string) (string, error)

func (*Manager) BackupIdentityForDIDReplacement

func (m *Manager) BackupIdentityForDIDReplacement(name string, plannedNewDID string) (string, error)

func (*Manager) BuildPaths

func (m *Manager) BuildPaths(dirName string) Paths

func (*Manager) Current

func (m *Manager) Current() (*IdentitySummary, error)

func (*Manager) EnsureRoot

func (m *Manager) EnsureRoot() error

func (*Manager) ImportAllLegacy

func (m *Manager) ImportAllLegacy() (*ImportResult, error)

func (*Manager) ImportLegacy

func (m *Manager) ImportLegacy(name string) (*ImportResult, error)

func (*Manager) LegacyRootDir

func (m *Manager) LegacyRootDir() string

func (*Manager) List

func (m *Manager) List() ([]IdentitySummary, error)

func (*Manager) Load

func (m *Manager) Load(name string) (*StoredIdentity, error)

func (*Manager) LoadIndex

func (m *Manager) LoadIndex() (IndexPayload, error)

func (*Manager) PathsForIdentity

func (m *Manager) PathsForIdentity(name string) (Paths, error)

func (*Manager) PreviewRecoverHandleBackupPath

func (m *Manager) PreviewRecoverHandleBackupPath(handle string) string

func (*Manager) PromoteRecoveredHandle

func (m *Manager) PromoteRecoveredHandle(finalIdentityName string, tempIdentityName string, archivedIdentityNames []string) (*StoredIdentity, bool, error)

func (*Manager) ReplaceIdentity

func (m *Manager) ReplaceIdentity(name string, input SaveInput) (*StoredIdentity, error)

func (*Manager) RootDir

func (m *Manager) RootDir() string

func (*Manager) Save

func (m *Manager) Save(input SaveInput) (*StoredIdentity, error)

func (*Manager) SaveIndex

func (m *Manager) SaveIndex(payload IndexPayload) error

func (*Manager) ScanLegacy

func (m *Manager) ScanLegacy() (*LegacyScan, error)

func (*Manager) SetDefault

func (m *Manager) SetDefault(name string) (*IdentitySummary, error)

func (*Manager) UpdateDisplayName

func (m *Manager) UpdateDisplayName(name string, displayName string) error

func (*Manager) UpdateJWT

func (m *Manager) UpdateJWT(name string, jwtToken string) error

type NormalizedHandle

type NormalizedHandle struct {
	LocalPart       string
	FullHandle      string
	EffectiveDomain string
	ExplicitDomain  bool
}

func NormalizeHandleInput

func NormalizeHandleInput(raw string, didDomain string) (*NormalizedHandle, error)

NormalizeHandleInput normalizes bare/full/wba handle input into a canonical full handle. DID inputs are rejected because callers should route those through explicit DID-aware command flags instead.

type Paths

type Paths struct {
	RootDir                  string `json:"root_dir"`
	DirName                  string `json:"dir_name"`
	IdentityDir              string `json:"identity_dir"`
	IdentityPath             string `json:"identity_path"`
	AuthPath                 string `json:"auth_path"`
	DIDDocumentPath          string `json:"did_document_path"`
	Key1PrivatePath          string `json:"key1_private_path"`
	Key1PublicPath           string `json:"key1_public_path"`
	E2EESigningPrivatePath   string `json:"e2ee_signing_private_path"`
	E2EEAgreementPrivatePath string `json:"e2ee_agreement_private_path"`
	E2EEStatePath            string `json:"e2ee_state_path"`
}

type RecoverFinalizeError

type RecoverFinalizeError struct {
	Err              error
	BackupPath       string
	TempIdentityName string
	NewDID           string
}

func (*RecoverFinalizeError) Error

func (e *RecoverFinalizeError) Error() string

func (*RecoverFinalizeError) Unwrap

func (e *RecoverFinalizeError) Unwrap() error

type RecoverParams

type RecoverParams struct {
	IdentityName string
	Handle       string
	Phone        string
	OTP          string
}

type RegisterParams

type RegisterParams struct {
	IdentityName        string
	Handle              string
	Phone               string
	Email               string
	OTP                 string
	InviteCode          string
	Wait                bool
	VerificationTimeout int
	PollIntervalSeconds float64
}

type RemoteClient

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

func NewRemoteClient

func NewRemoteClient(resolved *appconfig.Resolved) (*RemoteClient, error)

func (*RemoteClient) AuthenticatedRPCCall

func (c *RemoteClient) AuthenticatedRPCCall(ctx context.Context, endpoint string, method string, params any, auth *authsdk.Session, out any) error

func (*RemoteClient) AuthenticatedRPCCallProfile

func (c *RemoteClient) AuthenticatedRPCCallProfile(ctx context.Context, profile transportcfg.Profile, endpoint string, method string, params any, auth *authsdk.Session, out any) error

func (*RemoteClient) AuthenticatedRestPost

func (c *RemoteClient) AuthenticatedRestPost(ctx context.Context, endpoint string, requestPayload any, auth *authsdk.Session, out any) error

func (*RemoteClient) Client

func (c *RemoteClient) Client() *http.Client

func (*RemoteClient) LookupHandleByDID

func (c *RemoteClient) LookupHandleByDID(ctx context.Context, did string) (*HandleLookupResult, error)

func (*RemoteClient) RPCCall

func (c *RemoteClient) RPCCall(ctx context.Context, endpoint string, method string, params any, bearer string, out any) error

func (*RemoteClient) RestGet

func (c *RemoteClient) RestGet(ctx context.Context, endpoint string, query url.Values, out any) error

func (*RemoteClient) RestPost

func (c *RemoteClient) RestPost(ctx context.Context, endpoint string, requestPayload any, bearer string, out any) error

type ReplaceDIDParams

type ReplaceDIDParams struct {
	IdentityName string
	IsPublic     *bool
	IsAgent      *bool
	Role         *string
	EndpointURL  *string
}

type SaveInput

type SaveInput struct {
	IdentityName            string
	DID                     string
	UniqueID                string
	UserID                  string
	DisplayName             string
	Handle                  string
	FullHandle              string
	JWTToken                string
	DIDDocument             map[string]any
	Key1PrivatePEM          string
	Key1PublicPEM           string
	E2EESigningPrivatePEM   string
	E2EEAgreementPrivatePEM string
	ReplaceExisting         bool
}

type Service

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

func NewService

func NewService(resolved *appconfig.Resolved) (*Service, error)

func (*Service) Bind

func (s *Service) Bind(ctx context.Context, params BindParams) (*CommandResult, error)

func (*Service) Config

func (s *Service) Config() *appconfig.Resolved

func (*Service) Create

func (s *Service) Create(displayName string, identityName string) (*CommandResult, error)

func (*Service) Current

func (s *Service) Current() (*CommandResult, error)

func (*Service) FinalizeRecoveredHandle

func (s *Service) FinalizeRecoveredHandle(finalIdentityName string, tempIdentityName string, archivedIdentityNames []string, activeBefore string, backupPath string, newDID string) (*StoredIdentity, error)

func (*Service) GetProfile

func (s *Service) GetProfile(ctx context.Context, self bool, handle string, did string) (*CommandResult, error)

func (*Service) ImportV1

func (s *Service) ImportV1(name string, all bool) (*CommandResult, error)

func (*Service) List

func (s *Service) List() (*CommandResult, error)

func (*Service) Manager

func (s *Service) Manager() *Manager

func (*Service) Recover

func (s *Service) Recover(ctx context.Context, params RecoverParams) (*CommandResult, error)

func (*Service) RecoverPreview

func (s *Service) RecoverPreview(params RecoverParams) (*CommandResult, error)

func (*Service) RefreshToken

func (s *Service) RefreshToken(ctx context.Context, identityName string) (*CommandResult, error)

func (*Service) Register

func (s *Service) Register(ctx context.Context, params RegisterParams) (*CommandResult, error)

func (*Service) ReplaceDID

func (s *Service) ReplaceDID(ctx context.Context, params ReplaceDIDParams) (*CommandResult, error)

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, handle string, did string) (*CommandResult, error)

func (*Service) SetProfile

func (s *Service) SetProfile(ctx context.Context, params UpdateProfileParams) (*CommandResult, error)

func (*Service) Status

func (s *Service) Status() (*CommandResult, error)

func (*Service) Use

func (s *Service) Use(identityName string) (*CommandResult, error)

type ServiceError

type ServiceError struct {
	StatusCode int
	RPCCode    int
	Message    string
	Data       any
}

func (*ServiceError) Error

func (e *ServiceError) Error() string

type StoredIdentity

type StoredIdentity struct {
	IdentityName            string         `json:"identity_name"`
	DirName                 string         `json:"dir_name"`
	DID                     string         `json:"did"`
	UniqueID                string         `json:"unique_id"`
	UserID                  string         `json:"user_id,omitempty"`
	DisplayName             string         `json:"display_name,omitempty"`
	Handle                  string         `json:"handle,omitempty"`
	FullHandle              string         `json:"full_handle,omitempty"`
	CreatedAt               string         `json:"created_at,omitempty"`
	JWTToken                string         `json:"jwt_token,omitempty"`
	DIDDocument             map[string]any `json:"did_document,omitempty"`
	Key1PrivatePEM          string         `json:"key1_private_pem,omitempty"`
	Key1PublicPEM           string         `json:"key1_public_pem,omitempty"`
	E2EESigningPrivatePEM   string         `json:"e2ee_signing_private_pem,omitempty"`
	E2EEAgreementPrivatePEM string         `json:"e2ee_agreement_private_pem,omitempty"`
	IsDefault               bool           `json:"is_default,omitempty"`
}

type UpdateProfileParams

type UpdateProfileParams struct {
	DisplayName  string
	Bio          string
	TagsCSV      string
	Markdown     string
	MarkdownFile string
}

type UserState

type UserState struct {
	RegistrationState string   `json:"registration_state"`
	ReadyForMessaging bool     `json:"ready_for_messaging"`
	Missing           []string `json:"missing,omitempty"`
}

func EvaluateIdentitySummaryUserState

func EvaluateIdentitySummaryUserState(summary *IdentitySummary) UserState

func EvaluateStoredIdentityUserState

func EvaluateStoredIdentityUserState(record *StoredIdentity) UserState

func EvaluateUserState

func EvaluateUserState(userID string, handle string) UserState

Jump to

Keyboard shortcuts

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