@@ -30,6 +30,11 @@ public class Controller : IDisposable
3030 private byte [ ] deviceID ;
3131 private List < HomeKitEndPoint > endpoints = new List < HomeKitEndPoint > ( ) ;
3232
33+ /// <summary>
34+ /// Create a controller with a randomly generated key
35+ /// </summary>
36+ /// <param name="publicKey"></param>
37+ /// <param name="privateKey"></param>
3338 public Controller ( out byte [ ] publicKey , out byte [ ] privateKey )
3439 {
3540 byte [ ] seed = RandomNumberGenerator . GetBytes ( 32 ) ;
@@ -38,6 +43,13 @@ public Controller(out byte[] publicKey, out byte[] privateKey)
3843 publicKey = LTPK ;
3944 privateKey = LTSK ;
4045 }
46+
47+ /// <summary>
48+ /// Create a controller using the provided device ID and keys
49+ /// </summary>
50+ /// <param name="privateKey"></param>
51+ /// <param name="publicKey"></param>
52+ /// <param name="deviceID"></param>
4153 public Controller ( byte [ ] privateKey , byte [ ] publicKey , byte [ ] deviceID )
4254 {
4355 LTPK = publicKey ;
@@ -47,6 +59,15 @@ public Controller(byte[] privateKey, byte[] publicKey, byte[] deviceID)
4759
4860 public byte [ ] DeviceID { get { return deviceID ; } }
4961
62+ /// <summary>
63+ /// Connect to an already paired Accessory
64+ /// </summary>
65+ /// <param name="destination"></param>
66+ /// <param name="accessoryID"></param>
67+ /// <param name="accessoryLTPK"></param>
68+ /// <returns></returns>
69+ /// <exception cref="IOException"></exception>
70+ /// <exception cref="Exception"></exception>
5071 public async Task < HomeKitEndPoint > Connect ( IPEndPoint destination , byte [ ] accessoryID , byte [ ] accessoryLTPK )
5172 {
5273 X25519 session = new X25519 ( ) ;
@@ -58,7 +79,6 @@ public async Task<HomeKitEndPoint> Connect(IPEndPoint destination, byte[] access
5879 HttpResponseMessage msg = await con . Post ( "/pair-verify" , new TLVInt ( TLVType . kTLVType_State , ( byte ) PairingState . M1 ) , new TLVBytes ( TLVType . kTLVType_PublicKey , keyPair . Public ) ) ;
5980 if ( ! msg . IsSuccessStatusCode )
6081 throw new IOException ( $ "Pair Step 1 Failed with { msg . StatusCode } : { msg . ReasonPhrase } ") ;
61- Console . WriteLine ( "Step 1 Complete" ) ;
6282
6383 List < TLVValue > responseTLVs = TLVValue . CollectionFromStream ( msg . Content . ReadAsStream ( ) ) ;
6484 byte [ ] AccessorySessionPK = TLVValue . Concat ( TLVType . kTLVType_PublicKey , responseTLVs ) ;
@@ -89,7 +109,7 @@ public async Task<HomeKitEndPoint> Connect(IPEndPoint destination, byte[] access
89109 encryptedPayload = new byte [ encryptionPayload . Length + 16 ] ;
90110 encrypter . Encrypt ( Encoding . ASCII . GetBytes ( "\0 \0 \0 \0 PV-Msg03" ) , encryptionPayload . ToArray ( ) , encryptedPayload . AsSpan ( ) . Slice ( 0 , ( int ) encryptionPayload . Length ) , encryptedPayload . AsSpan ( ) . Slice ( ( int ) encryptionPayload . Length , 16 ) ) ;
91111 }
92- Console . WriteLine ( "Submitting Step 3" ) ;
112+
93113 msg = await con . Post ( "/pair-verify" , [
94114 new TLVInt ( TLVType . kTLVType_State , ( byte ) PairingState . M3 ) ,
95115 new TLVBytes ( TLVType . kTLVType_EncryptedData , encryptedPayload )
@@ -100,7 +120,6 @@ public async Task<HomeKitEndPoint> Connect(IPEndPoint destination, byte[] access
100120 throw new IOException ( $ "Verify Step 3 Failed with { msg . StatusCode } : { msg . ReasonPhrase } : { content } ") ;
101121 }
102122 responseTLVs = TLVValue . CollectionFromStream ( msg . Content . ReadAsStream ( ) ) ;
103- Console . WriteLine ( "Completed Step 3" ) ;
104123
105124 bool complete = responseTLVs . Any ( t => t . Type == TLVType . kTLVType_State ) ;
106125
@@ -124,6 +143,11 @@ public async Task<HomeKitEndPoint> Connect(IPEndPoint destination, byte[] access
124143 throw new Exception ( "Failed to Connect - Cause Unknown" ) ;
125144 }
126145
146+ /// <summary>
147+ /// Unpair from an already paired accessory
148+ /// </summary>
149+ /// <param name="endpoint"></param>
150+ /// <returns></returns>
127151 public async Task < bool > UnPair ( HomeKitEndPoint endpoint )
128152 {
129153 HttpResponseMessage msg = await endpoint . Connection . Post ( "/pair-setup" ,
@@ -137,6 +161,13 @@ public async Task<bool> UnPair(HomeKitEndPoint endpoint)
137161 return true ;
138162 }
139163
164+ /// <summary>
165+ /// Pair to an unpaired accessory
166+ /// </summary>
167+ /// <param name="setupPin"></param>
168+ /// <param name="destination"></param>
169+ /// <returns></returns>
170+ /// <exception cref="IOException"></exception>
140171 public async Task < AccessoryInfo > Pair ( long setupPin , IPEndPoint destination )
141172 {
142173 string I = "Pair-Setup" ;
0 commit comments