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
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
Methods:¶
__init__(app, device=None, secret=None, *, require_firmware_mode=False)
¶
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 (and require_firmware_mode is not set), 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
|
require_firmware_mode
|
bool
|
If True, fail if the device is not in firmware mode instead of attempting to use an already running application. |
False
|
Raises:
| Type | Description |
|---|---|
TKeyNotFoundError
|
If the TKey device cannot be found. |
TKeyNotInFirmwareModeError
|
when require_firmware_mode is set and the device is not in firmware mode. |
TKeyUnexpectedAppError
|
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. Streaming messages of arbitrary size are supported for ML-DSA. For Ed25519, the message (or stream) must not exceed 4096 bytes.
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
|
SignableMessage
|
The raw bytes, binary reader (file-like object), or chunk iterable to sign. For Ed25519, the total message size cannot exceed 4096B. This limitation does not apply to ML-DSA as FIPS 204 external mu is used. |
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
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Attributes¶
digest
property
¶
Return the SHA-512 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.
Warning
When Ed25519 is used, there is a 4096B size limit to signing payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
int | None
|
The version of the signer application to load. |
None
|
digest
|
str | None
|
A SHA-512 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 SHA-512 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). |