API Reference¶
This page documents the classes used for signing payloads with the Tillitis TKey. The common usage pattern is:
- Construct device application configuration with
SignApp.load_mldsa()orSignApp.load_ed25519()- If this is the first use of the key, store the app digest
- On subsequent uses, provide the same app digest to
load_mldsa()orload_ed25519()
- Initialize a
TKeySignsigner using the application configuration: this loads the application onto the device - Use the signer to sign payloads
TKey Signer Client¶
keylet.TKeySign
¶
Bases: TKey
Client for communicating with the TKey signer application.
This class implements public key retrieval and signing as defined in the tkey-pq-device-signer protocol but is also compatible with the tkey-device-signer protocol.
Source code in src/keylet/tkey_sign.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
Methods:¶
__init__(app, device=None, secret=None)
¶
Initialize the TKey signing client.
If the TKey device is in firmware mode, this will automatically load the application binary. If the device is already running an application, it verifies that the running application matches the expected name and version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
SignApp
|
The SignApp configuration containing the binary and metadata. |
required |
device
|
str | None
|
Optional serial port path (e.g., |
None
|
secret
|
str | None
|
Optional User Supplied Secret (passphrase) used as a seed for key derivation. |
None
|
Raises:
| Type | Description |
|---|---|
TKeyNotFoundError
|
If the TKey device cannot be found. |
TKeyAppError
|
If loading the application fails or the device is running a mismatched application. |
TKeyError
|
For other connection or initialization failures. |
Source code in src/keylet/tkey_sign.py
get_pubkey()
¶
Retrieve the public key bytes from the TKey device.
Returns:
| Type | Description |
|---|---|
bytes
|
The raw public key bytes. |
Raises:
| Type | Description |
|---|---|
TKeyIOError
|
If reading from the serial port fails. |
TKeyProtocolError
|
If there is a framing or protocol mismatch. |
Source code in src/keylet/tkey_sign.py
sign(message, pub_key=None)
¶
Sign a payload.
Sends payload to device and retrieves the signature.
For ML-DSA, the FIPS 204 external mu is computed using the message and public key: the mu is sent to device instead of payload.
Note
This method blocks and waits (up to 60 seconds) for the user to touch the physical TKey device when it flashes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
bytes
|
The raw bytes of the message/payload to sign. |
required |
pub_key
|
bytes | None
|
The public key bytes (only needed for ML-DSA). If not provided, key is retrieved from device. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
The generated signature as raw bytes. |
Raises:
| Type | Description |
|---|---|
TKeyError
|
If the device returns a bad status during signing. |
TKeyIOError
|
If writing or reading from the serial port fails. |
TKeyProtocolError
|
If there is a framing or protocol mismatch. |
Source code in src/keylet/tkey_sign.py
Device Application Configuration¶
keylet.SignApp
dataclass
¶
Configuration and binary data for the TKey device signer application.
Attributes:
| Name | Type | Description |
|---|---|---|
binary |
bytes
|
The raw bytes of the device application binary. |
version |
int
|
The version number of the device application. |
name |
tuple[str, str]
|
Device application name tuple. |
sig_size |
int
|
The size of the generated signature in bytes. |
key_size |
int
|
The size of the public key in bytes. |
Source code in src/keylet/tkey_sign.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Attributes¶
digest
property
¶
Return the BLAKE2s-256 hex digest of the application binary.
Methods:¶
load_ed25519(version=None, digest=None)
classmethod
¶
Load a Ed25519 signer application from package resources.
If a digest (or prefix) is provided, it returns the binary matching the digest. If a version is provided, it filters by version. If neither is provided, current default binary is loaded.
TKey key derivation depends on the application binary, so users who want a specific key must provide the binary digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
int | None
|
The version of the signer application to load. |
None
|
digest
|
str | None
|
A BLAKE2s-256 hex digest (or prefix) of the target binary. |
None
|
Returns:
| Type | Description |
|---|---|
SignApp
|
An instance of SignApp configured with the loaded binary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no binary matches the criteria, or if the search is ambiguous (matches multiple binaries). |
Source code in src/keylet/tkey_sign.py
load_mldsa(version=None, digest=None)
classmethod
¶
Load a ML-DSA signer application from package resources.
If a digest (or prefix) is provided, it returns the binary matching the digest. If a version is provided, it filters by version. If neither is provided, current default binary is loaded.
TKey key derivation depends on the application binary, so users who want a specific key must provide the binary digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
int | None
|
The version of the signer application to load. |
None
|
digest
|
str | None
|
A BLAKE2s-256 hex digest (or prefix) of the target binary. |
None
|
Returns:
| Type | Description |
|---|---|
SignApp
|
An instance of SignApp configured with the loaded binary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no binary matches the criteria, or if the search is ambiguous (matches multiple binaries). |