@@ -74,17 +74,43 @@ def adv_key_b64(self) -> str:
7474 """Return the advertised (public) key as a base64-encoded string."""
7575 return base64 .b64encode (self .adv_key_bytes ).decode ("ascii" )
7676
77+ @property
78+ @override
79+ def hashed_adv_key_bytes (self ) -> bytes :
80+ """See `HasHashedPublicKey.hashed_adv_key_bytes`."""
81+ return hashlib .sha256 (self .adv_key_bytes ).digest ()
82+
7783 @property
7884 def mac_address (self ) -> str :
7985 """Get the mac address from the public key."""
8086 first_byte = (self .adv_key_bytes [0 ] | 0b11000000 ).to_bytes (1 )
8187 return ":" .join ([parsers .format_hex_byte (x ) for x in first_byte + self .adv_key_bytes [1 :6 ]])
8288
83- @property
84- @override
85- def hashed_adv_key_bytes (self ) -> bytes :
86- """See `HasHashedPublicKey.hashed_adv_key_bytes`."""
87- return hashlib .sha256 (self .adv_key_bytes ).digest ()
89+ def adv_data (self , status : int = 0 , hint : int = 0 ) -> bytes :
90+ """Get the BLE advertisement data that should be broadcast to advertise this key."""
91+ return bytes (
92+ [
93+ # apple company id
94+ 0x4C ,
95+ 0x00 ,
96+ ],
97+ ) + self .of_data (status , hint )
98+
99+ def of_data (self , status : int = 0 , hint : int = 0 ) -> bytes :
100+ """Get the Offline Finding data that should be broadcast to advertise this key."""
101+ return bytes (
102+ [
103+ # offline finding
104+ 0x12 ,
105+ # offline finding data length
106+ 25 ,
107+ status ,
108+ # remaining public key bytes
109+ * self .adv_key_bytes [6 :],
110+ self .adv_key_bytes [0 ] >> 6 ,
111+ hint ,
112+ ],
113+ )
88114
89115
90116class KeyPair (HasPublicKey ):
0 commit comments