Switch to prefixed IDs and tell agents which Mac a message came from

This commit is contained in:
Ian Gulliver
2026-10-20 23:15:19 -07:00
parent f1296ba13d
commit 59bf17189d
42 changed files with 770 additions and 145 deletions
+22
View File
@@ -0,0 +1,22 @@
import CryptoKit
import Foundation
private let idAlphabet = Array("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
func newID(_ prefix: String) -> String {
prefix + String((0..<11).map { _ in idAlphabet.randomElement()! })
}
// IDs from before prefixed IDs were 12 lowercase hex characters; the server renamed each to this same derivation.
func migratedID(_ prefix: String, _ old: String) -> String {
guard old.count == 12, old.allSatisfy({ "0123456789abcdef".contains($0) }) else {
return old
}
var n = SHA256.hash(data: Data(old.utf8)).prefix(8).reduce(UInt64(0)) { $0 << 8 | UInt64($1) }
var out = ""
for _ in 0..<11 {
out.append(idAlphabet[Int(n % UInt64(idAlphabet.count))])
n /= UInt64(idAlphabet.count)
}
return prefix + out
}