Documentation
¶
Overview ¶
Package credentials shares remote-service credentials between family apps (spec §8): one login-Keychain item per vendor account (service "ActNow", account "vendor.<id>", written with /usr/bin/security), and credentials.json for what is not secret (a hint, a fingerprint, which apps use it). An app reads a shared secret only after the user agreed in that app ("Use this key"), which adds it to the vendor's users.
Index ¶
- Constants
- Variables
- func Account(vendor string) string
- func Fingerprint(secret string) string
- func Hint(secret string) string
- func KeychainGuarded() (bool, string)
- func ParseRef(ref string) (vendor string, ok bool)
- func Ref(vendor string) string
- func RunSecurity(stdin string, args ...string) ([]byte, []byte, error)
- type Entry
- type File
- type Keychain
- type Legacy
- type SaveOptions
- type Store
- func (s *Store) Compare(vendor, secret string) (shared, same bool)
- func (s *Store) DeleteForAll(ctx context.Context, vendor string) error
- func (s *Store) Forget(ctx context.Context, vendor string) error
- func (s *Store) MigrateLegacy(ctx context.Context, vendor string, old Legacy, opts SaveOptions) error
- func (s *Store) Offer(vendor string) (Entry, bool)
- func (s *Store) OtherUsers(vendor string) []string
- func (s *Store) Save(ctx context.Context, vendor, secret string, opts SaveOptions) error
- func (s *Store) Secret(ctx context.Context, vendor string) (string, error)
- func (s *Store) StopUsing(ctx context.Context, vendor string) error
- func (s *Store) Use(ctx context.Context, vendor string) (string, error)
- func (s *Store) Using(vendor string) bool
- type Vendor
Constants ¶
const ( EnvNoKeychain = "ACTNOW_NO_KEYCHAIN" EnvKeychainFile = "ACTNOW_KEYCHAIN_FILE" )
EnvNoKeychain set to "1" keeps every Keychain of the process away from the macOS Keychain (scripted checks, CI): the items go to a stand-in file (EnvKeychainFile, else $HOME/.actnow-keychain-standin.json).
const ( AuthAPIKey = "apiKey" AuthAppIDAccessToken = "appId+accessToken" // Doubao speech: the App ID is not secret AuthToken = "token" // Hugging Face access token )
Auth kinds of a vendor's credential.
const Kind = "credentials"
Kind is the schema kind of credentials.json.
const Service = "ActNow"
Service is the Keychain service of the family's shared secrets.
Variables ¶
var ( ErrNotFound = errors.New("no such Keychain item") ErrNoKeychain = errors.New("no Keychain on this system") )
Errors of the Keychain.
var ( ErrUnknownVendor = errors.New("unknown vendor") // ErrNotConsented: this app is not among the vendor's users; ask the // user first (TextUseKeyFrom) and call Use. ErrNotConsented = errors.New("the user has not agreed to use this shared key in this app") // ErrMissing: the metadata names a key whose Keychain item is gone // (deleted in Keychain Access): ask for the key again. ErrMissing = errors.New("the shared key is no longer in the Keychain") )
Errors of the Store.
var ( TextUseKeyFrom = family.Text{EN: "Use the {vendor} key from {app} ({hint})", ZH: "使用 {app} 中的 {vendor} 密钥({hint})"} TextUseThisKey = family.Text{EN: "Use this key", ZH: "使用此密钥"} TextEnterAnother = family.Text{EN: "Enter another key", ZH: "输入其他密钥"} TextFoundKeys = family.Text{ EN: "Found API keys in other ActNow apps: {vendors}. Use them in {app}?", ZH: "在其他 ActNow app 中找到 API 密钥:{vendors}。要在 {app} 中使用吗?", } TextUseThem = family.Text{EN: "Use them", ZH: "使用"} TextNotNow = family.Text{EN: "Not now", ZH: "暂不"} // Deprecated: use TextAlsoUpdatesShared (v0.22.1), which names no apps. TextAlsoUpdates = family.Text{EN: "Also updates it in {apps}.", ZH: "{apps} 中也会一并更新。"} // TextAlsoUpdatesShared: under a shared key, without the apps' names. TextAlsoUsesKey = family.Text{EN: "{apps} also uses this key.", ZH: "{apps} 也在使用此密钥。"} TextStopHere = family.Text{EN: "Stop using it here", ZH: "仅在此处停用"} TextDeleteAll = family.Text{EN: "Delete for all apps", ZH: "为所有 app 删除"} TextDifferentKey = family.Text{EN: "{app} has a different {vendor} key.", ZH: "{app} 中的 {vendor} 密钥与此不同。"} TextSecurityHelp = family.Text{ EN: "Shared keys are stored in your login keychain. Like each app's own keys, other programs you run can read them with the security tool.", ZH: "共享密钥保存在登录钥匙串中。与各 app 自己保存的密钥一样,你运行的其他程序可以通过 security 工具读取它们。", } )
Reference texts (spec §8.3).
var OnSecurity func(args ...string)
OnSecurity, when set, is called before every run of /usr/bin/security (with its arguments): tests and scripted checks prove a guarded process never runs it.
var Vendors = []Vendor{ {ID: "openai", Name: "OpenAI", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.openai"), llm("auralink", "llm.openai"), llm("auralink", "asr.openai")}, Note: "Auralink's OpenAI-compatible ASR with a custom endpoint is not this vendor."}, {ID: "anthropic", Name: "Anthropic", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.anthropic"), llm("auralink", "llm.anthropic")}}, {ID: "deepseek", Name: "DeepSeek", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.deepseek"), llm("auralink", "llm.deepseek")}}, {ID: "dashscope", Name: "Alibaba Cloud Model Studio (China)", NameZH: "阿里云百炼(中国站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.dashscope"), llm("auralink", "llm.dashscope"), llm("auralink", "asr.aliyun")}, Note: "One DashScope key serves both ASR and LLM."}, {ID: "dashscope-intl", Name: "Alibaba Cloud Model Studio (International)", NameZH: "阿里云百炼(国际站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.dashscope-intl"), llm("auralink", "llm.dashscope-intl")}}, {ID: "stepfun", Name: "StepFun", NameZH: "阶跃星辰", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.stepfun"), llm("auralink", "asr.stepfun")}}, {ID: "volcengine-ark", Name: "Volcano Engine Ark", NameZH: "火山方舟", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.volcengine")}, Note: "Not the same credential as Doubao speech."}, {ID: "volcengine-speech", Name: "Doubao Speech", NameZH: "豆包语音", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "asr.doubao")}, Note: "Either an API key, or an App ID (not secret, kept in credentials.json) and an access token."}, {ID: "moonshot", Name: "Kimi (moonshot.cn)", NameZH: "Kimi(中国站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.moonshot"), llm("auralink", "llm.moonshot")}, Note: "AudioSmith's llm.moonshot served both sites: its base URL decides (VendorForLegacy)."}, {ID: "moonshot-intl", Name: "Kimi (moonshot.ai)", NameZH: "Kimi(国际站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.moonshot-intl")}}, {ID: "siliconflow", Name: "SiliconFlow (siliconflow.cn)", NameZH: "硅基流动(中国站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "llm.siliconflow"), llm("auralink", "llm.siliconflow")}, Note: "AudioSmith's llm.siliconflow served both sites: its base URL decides (VendorForLegacy)."}, {ID: "siliconflow-intl", Name: "SiliconFlow (siliconflow.com)", NameZH: "硅基流动(国际站)", Auth: AuthAPIKey, Legacy: []Legacy{llm("auralink", "llm.siliconflow-intl")}}, {ID: "zhipu", Name: "Zhipu AI", NameZH: "智谱 AI", Auth: AuthAPIKey, Legacy: both("llm.zhipu")}, {ID: "minimax", Name: "MiniMax", Auth: AuthAPIKey, Legacy: both("llm.minimax")}, {ID: "mimo", Name: "Xiaomi MiMo", NameZH: "小米 MiMo", Auth: AuthAPIKey, Legacy: both("llm.mimo")}, {ID: "gemini", Name: "Google Gemini", Auth: AuthAPIKey, Legacy: both("llm.gemini")}, {ID: "xai", Name: "xAI", Auth: AuthAPIKey, Legacy: both("llm.xai")}, {ID: "groq", Name: "Groq", Auth: AuthAPIKey, Legacy: both("llm.groq")}, {ID: "mistral", Name: "Mistral AI", Auth: AuthAPIKey, Legacy: both("llm.mistral")}, {ID: "together", Name: "Together AI", Auth: AuthAPIKey, Legacy: both("llm.together")}, {ID: "fireworks", Name: "Fireworks AI", Auth: AuthAPIKey, Legacy: both("llm.fireworks")}, {ID: "cerebras", Name: "Cerebras", Auth: AuthAPIKey, Legacy: both("llm.cerebras")}, {ID: "nvidia", Name: "NVIDIA NIM", Auth: AuthAPIKey, Legacy: both("llm.nvidia")}, {ID: "openrouter", Name: "OpenRouter", Auth: AuthAPIKey, Legacy: both("llm.openrouter")}, {ID: "deepl", Name: "DeepL", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.deepl")}}, {ID: "google-translate", Name: "Google Cloud Translation", NameZH: "Google 翻译", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.google")}, Note: "mt.google-v3 is an OAuth token and is not shared."}, {ID: "microsoft-translator", Name: "Microsoft Translator", NameZH: "微软翻译", Auth: AuthAPIKey, Legacy: []Legacy{llm("audiosmith", "mt.microsoft")}}, {ID: "huggingface", Name: "Hugging Face", Auth: AuthToken, Legacy: []Legacy{llm("audiosmith", "huggingface-token"), llm("dicta", "huggingface-token")}}, }
Vendors is the vendor table. New vendors only add rows.
Functions ¶
func Fingerprint ¶
Fingerprint is "sha256:" and the first 12 hex digits of the secret's SHA-256: enough to tell whether two apps hold the same key, nothing more (spec §8.2).
func Hint ¶
Hint shows a secret as the UI may: its prefix ("sk-", "hf_") and last 4 characters, "sk-…a1b2"; short secrets show nothing.
func KeychainGuarded ¶ added in v0.22.0
KeychainGuarded reports whether this process keeps away from the macOS Keychain (and why): its Keychains then use a stand-in file.
func ParseRef ¶
ParseRef returns the vendor of a credentialRef; ok false when it is not a shared one.
Types ¶
type Entry ¶
type Entry struct {
Account string `json:"account"` // "vendor.deepseek"
Auth string `json:"auth"`
AppID string `json:"appId,omitempty"` // Doubao speech's App ID
Hint string `json:"hint"`
Fingerprint string `json:"fingerprint"`
AddedBy string `json:"addedBy"` // bundle id
Updated time.Time `json:"updated"`
Users []string `json:"users"` // bundle ids that agreed to use it
Extra family.Extra `json:"-"`
}
Entry is a shared vendor credential's metadata in credentials.json. Never a secret: hint and fingerprint only.
func (Entry) MarshalJSON ¶
func (*Entry) UnmarshalJSON ¶
type File ¶
type File struct {
Schema string `json:"schema"`
Rev int `json:"rev"`
Vendors map[string]Entry `json:"vendors"`
Extra family.Extra `json:"-"`
}
File is credentials.json (multi-writer, locks/credentials.lock).
func (File) MarshalJSON ¶
func (*File) UnmarshalJSON ¶
type Keychain ¶
type Keychain struct {
// Service is the items' service; "" = Service ("ActNow"). Apps also
// use a Keychain with their own service to read legacy items.
Service string
// File is a keychain file to use instead of the login keychain
// (tests: the login keychain is locked in SSH sessions).
File string
// Run runs security with args and stdin and returns its standard
// output and error; nil = /usr/bin/security (tests replace it), or,
// when the process must keep away from the Keychain (KeychainGuarded:
// a HOME that is not the user's, ACTNOW_NO_KEYCHAIN=1), a stand-in
// file. A missing item is ErrNotFound.
Run func(stdin string, args ...string) (stdout, stderr []byte, err error)
}
Keychain is generic-password items of the login keychain, read and written by /usr/bin/security as the apps already do (spec §8.2): no -T, so any process of the user running security can read them — the same protection the apps' own items have today. Every method may block: call them off the main thread.
func (Keychain) Get ¶
Get reads a secret; ErrNotFound when there is no item. It uses -g rather than -w: -w prints secrets with non-printable characters (and quotes, backslashes, non-ASCII) as bare hex, which cannot be told apart from a secret made of hex digits; -g marks hex with "0x".
type Legacy ¶
type Legacy struct {
App string // app id
Service string // Keychain service: the app's name
Account string
}
Legacy is a secret an app kept under its own service before the spec ("AudioSmith" / "llm.deepseek"). Migration copies it to the shared item once the user agrees.
type SaveOptions ¶
type SaveOptions struct {
// AppID is Doubao speech's App ID (Auth AuthAppIDAccessToken).
AppID string
// Auth overrides the vendor's default auth kind.
Auth string
}
SaveOptions are extra fields of Save.
type Store ¶
Store is one app's access to the shared credentials.
func (*Store) Compare ¶
Compare tells whether an app's own key for a vendor is the shared one (spec §15.2 step 6: different keys are never merged; the consumer shows TextDifferentKey and lets the user choose). shared is false when the vendor has no shared key.
func (*Store) DeleteForAll ¶
DeleteForAll removes the Keychain item and its metadata.
func (*Store) MigrateLegacy ¶
func (s *Store) MigrateLegacy(ctx context.Context, vendor string, old Legacy, opts SaveOptions) error
MigrateLegacy copies an app's old item (e.g. "AudioSmith"/"llm.deepseek") to the shared item after the user agreed to share it, reads it back to check, and joins the users. The old item is kept until the app's next major version (spec §15.2 step 6).
func (*Store) Offer ¶
Offer returns the shared credential of a vendor, if any, for the consumer's prompt "Use the DeepSeek key from Auralink (sk-…a1b2)". It never reads the secret.
func (*Store) OtherUsers ¶
OtherUsers are the vendor's users besides this app, for "Auralink also uses this key" before deleting.
func (*Store) Save ¶
Save stores a key the user entered in this app with "Let other ActNow apps on this Mac use this key" checked (spec §8.3): the Keychain item "ActNow"/"vendor.<id>" is written (replacing another app's key for the same vendor: TextAlsoUpdates) and this app joins its users.
func (*Store) Secret ¶
Secret reads the vendor's shared key for an app that agreed to use it (ErrNotConsented otherwise: never read it before the user agreed, not even for a connection test). A missing item drops the metadata and returns ErrMissing.
func (*Store) StopUsing ¶
StopUsing is "Stop using it here": this app leaves the users; the key stays for the others.
type Vendor ¶
type Vendor struct {
ID string
Name string // English display name
NameZH string // Chinese display name ("" = Name)
Auth string
Legacy []Legacy
Note string
}
Vendor is a row of the vendor table (spec §8.1): one account on one platform, whatever an app uses it for (ASR, LLM).
func VendorForLegacy ¶
VendorForLegacy finds the vendor of an app's old Keychain account ("audiosmith", "llm.deepseek"). baseURL is the provider's endpoint, which decides the site for accounts that served two (AudioSmith's llm.moonshot, llm.siliconflow); "" picks the Chinese site. An OpenAI account with a custom (non-api.openai.com) endpoint is not shared.