The best way to control Claude Code, Codex and more from any computer or phone

main
swift 20 lines 804 Bytes
Raw
1 import CryptoKit
2 import Foundation
3
4 /// P-256 keys for DPoP proofs, as 32-byte private scalars and 65-byte uncompressed public points.
5 enum T3DpopKeys {
6 /// The private scalar followed by the public point.
7 static func generate() -> Data {
8 let key = P256.Signing.PrivateKey()
9 return key.rawRepresentation + key.publicKey.x963Representation
10 }
11
12 static func matches(privateKey: Data, publicKey: Data) throws -> Bool {
13 try P256.Signing.PrivateKey(rawRepresentation: privateKey).publicKey.x963Representation == publicKey
14 }
15
16 /// ES256 over the JWS signing input, as the raw `r‖s` pair JWS uses.
17 static func sign(privateKey: Data, signingInput: Data) throws -> Data {
18 try P256.Signing.PrivateKey(rawRepresentation: privateKey).signature(for: signingInput).rawRepresentation
19 }
20 }