// The password channel: what Cotton Keys' credential provider tells the app// about passwords.//// The THIRD KIND of mailbox, in the share channel's spelling (`ShareMailbox`,// one App Group `UserDefaults` key, raw-JSON append, drained whole), under// its own key so the passkey drain never takes a password entry (it drops a// kind it does not know) and this one never takes a passkey's://// password.used {password_id, used_at} a fill, to stamp last_used_at// password.saved {pending_id, site, username, a site's form handed a login// title} to save (iOS 26.2)//// NO PASSWORD EVER RIDES HERE: a saved password waits in the shared keychain// group's pending store (`PasswordKeychain.pending()`) under `pending_id`,// read by the app for the one `password.save` call that seals it, then// removed. The knock is the passkey channel's (`PasskeyChannel.knock`): one// Darwin notification wakes Keys for both drains.importFoundation/// The channel's names.publicenumPasswordChannel {/// The App Group `UserDefaults` key. Wire protocol, like the share key.publicstaticlet mailboxKey = "cotton.password.mailbox.v1"/// The two kinds an entry is.publicstaticlet used = "password.used"publicstaticlet saved = "password.saved"}/// One thing the provider did with a password, as it wrote it down.publicstructPasswordEntry: Codable, Equatable, Sendable {publicvar id: String/// When the provider wrote it, ISO-8601.publicvar at: String/// ``PasswordChannel/used`` or ``PasswordChannel/saved``.publicvar kind: String/// The `secret` row a fill used.publicvar passwordId: String?publicvar usedAt: String?/// The pending keychain item a save's password waits in.publicvar pendingId: String?publicvar site: String?publicvar username: String?publicvar title: String?publicinit( id: String = UUID().uuidString, at: String, kind: String, passwordId: String? = nil, usedAt: String? = nil, pendingId: String? = nil, site: String? = nil, username: String? = nil, title: String? = nil ) {self.id = idself.at = atself.kind = kindself.passwordId = passwordIdself.usedAt = usedAtself.pendingId = pendingIdself.site = siteself.username = usernameself.title = title }privateenumCodingKeys: String, CodingKey {case id, at, kind, site, username, titlecase passwordId = "password_id"case usedAt = "used_at"case pendingId = "pending_id" }}/// The password mailbox: ``ShareMailbox`` under ``PasswordChannel/mailboxKey``.publicstructPasswordMailbox: Sendable {privatelet mailbox: ShareMailboxpublicinit(storage: any ShareMailboxStorage = DefaultsShareMailboxStorage()) { mailbox = ShareMailbox(storage: storage, key: PasswordChannel.mailboxKey) }publicfunc append(_ entry: PasswordEntry) { mailbox.append(entry) }/// Take everything waiting, removing the list.publicfunc drain() -> [PasswordEntry] { mailbox.drain(PasswordEntry.self) }/// Put entries back to wait for a later drain (the vault was locked).publicfunc wait(_ entries: [PasswordEntry]) {for entry in entries { mailbox.append(entry) } }/// What is waiting, without taking it.publicfunc waiting() -> [PasswordEntry] { mailbox.peek(PasswordEntry.self) }}