generateAPIKey mints a random key with a scope-revealing prefix (Slice 5a): e2a_acct_… for account keys, e2a_agt_… for agent keys. The prefix is cosmetic for validation (keys are matched by hash of the full string), but makes a key's blast radius obvious wherever it's pasted or logged. Legacy `e2a_…
(scope string)
| 3566 | // keys minted before this change keep validating — the hash is over the whole |
| 3567 | // string, so the prefix change only affects newly minted keys. |
| 3568 | func generateAPIKey(scope string) string { |
| 3569 | b := make([]byte, 32) |
| 3570 | if _, err := rand.Read(b); err != nil { |
| 3571 | // Same reasoning as generateID — an all-zero API key would be |
| 3572 | // catastrophic (predictable auth credential). |
| 3573 | panic(fmt.Sprintf("identity: crypto/rand failed: %v", err)) |
| 3574 | } |
| 3575 | prefix := "e2a_acct_" |
| 3576 | if scope == ScopeAgent { |
| 3577 | prefix = "e2a_agt_" |
| 3578 | } |
| 3579 | return prefix + hex.EncodeToString(b) |
| 3580 | } |
| 3581 | |
| 3582 | // randomHex32 returns 32 bytes of crypto-random data hex-encoded. Shared by the |
| 3583 | // session-token path; panics on RNG failure (same reasoning as generateID). |
no test coverage detected