Skip to main content

thru_base/
signer.rs

1//! Bring-your-own-signer surface (external-signer Workstream B).
2//!
3//! Lets a custody partner (e.g. one using a Blockdaemon Builder Vault TSM) sign
4//! Thru transactions without the SDK ever holding a key: build the exact bytes
5//! `M` the external signer must sign, hand `M` to the HSM/MPC backend, then
6//! attach the returned signature with a verify-before-attach check.
7//!
8//! `SigningMessage` is opaque and constructible only by the domain builders, so
9//! a caller cannot steer a signer to arbitrary bytes or a mismatched domain.
10//! `attach_signature` runs the strict/canonical verifier before accepting a
11//! signature, so a wrong-key or garbage signature fails locally rather than on
12//! chain.  `LocalSigner` is a key-holding control implementation (kept out of any
13//! key-free core).  See specs/mpc-hsm-signer-design.md §4.2.
14//!
15//! Beyond the opaque 48-byte transaction message, a `Signer` can also be asked to
16//! sign in terms of *semantic* inputs: the full transaction body
17//! ([`Signer::sign_transaction_body`]), a user message ([`Signer::sign_message`])
18//! or an EOA create/delete authorization ([`Signer::sign_eoa_auth`]).  Hardware
19//! signers (e.g. a Ledger) need these inputs rather than pre-built bytes so they
20//! can parse and display what is being signed and construct the domain-separated
21//! message themselves.  The `*_with` helpers wrap each operation with a
22//! fail-fast key check and a strict verify of the returned signature.
23
24use crate::tn_signature::{self, SignatureDomain};
25use crate::txn_lib::TnPubkey;
26use crate::txn_tools::{build_eoa_create_message, build_eoa_delete_message};
27use ed25519_dalek::{Signer as _, SigningKey};
28use std::fmt;
29
30/// Maximum size, in bytes, of an off-chain message accepted by
31/// [`sign_message_with`] (`tn_msg_sign_v1__` domain).
32pub const MAX_MESSAGE_SZ: usize = 32 * 1024;
33
34#[derive(Debug)]
35pub enum SignError {
36    /// The signer's public key does not match the message's expected key.
37    KeyMismatch { expected: [u8; 32], got: [u8; 32] },
38    /// The signature does not verify over the message (wrong key or garbage;
39    /// Ed25519 has no key recovery, so the two are indistinguishable here).
40    InvalidSignature,
41    /// The signer (or an approver) declined.
42    Rejected,
43    /// A backend-specific error.
44    Backend(String),
45    /// The signer does not support this operation (for example a signer that
46    /// only signs transactions was asked to sign an EOA authorization).
47    Unsupported(String),
48}
49
50impl fmt::Display for SignError {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        match self {
53            SignError::KeyMismatch { .. } => {
54                write!(f, "signer public key does not match expected key")
55            }
56            SignError::InvalidSignature => write!(f, "invalid signature"),
57            SignError::Rejected => write!(f, "signing rejected"),
58            SignError::Backend(s) => write!(f, "signer backend error: {s}"),
59            SignError::Unsupported(s) => write!(f, "operation not supported by signer: {s}"),
60        }
61    }
62}
63impl std::error::Error for SignError {}
64
65/// Byte offset of the fee-payer public key within a transaction body (the fixed
66/// `WireTxnHdrV1` header; see `txn_lib::WireTxnHdrV1`).
67const TXN_FEE_PAYER_OFFSET: usize = 48;
68/// Length of the fixed transaction wire header — the minimum body length.
69const TXN_HEADER_SZ: usize = 112;
70
71/// An opaque, frozen transaction signing message: the exact bytes `M` an
72/// external signer signs (48 bytes), the fee-payer key the signature must verify
73/// under (derived from the body, never independent caller input), and an
74/// immutable snapshot of the body so `attach_signature` can emit a self-consistent
75/// signed wire even if the caller later mutates its original buffer.
76#[derive(Clone)]
77pub struct SigningMessage {
78    m: Vec<u8>,
79    expected_pubkey: [u8; 32],
80    body: Vec<u8>,
81}
82
83impl SigningMessage {
84    /// The exact bytes to sign — hand these to the HSM/MPC backend.
85    pub fn as_bytes(&self) -> &[u8] {
86        &self.m
87    }
88    /// The public key the signature must verify under: the fee-payer taken from
89    /// the transaction body, so it cannot disagree with what the chain checks.
90    pub fn expected_pubkey(&self) -> &[u8; 32] {
91        &self.expected_pubkey
92    }
93    /// The transaction body snapshot these bytes were built from.
94    pub fn body(&self) -> &[u8] {
95        &self.body
96    }
97}
98
99/// Build the signing message for a transaction: `M = DST_TXN ‖ SHA-256(body)`,
100/// where `body` is the wire bytes preceding the trailing signature.  The
101/// signature's expected key is the fee-payer taken from the body header (offset
102/// 48), *not* an independent argument — so a caller cannot pair a body owned by
103/// fee-payer A with a signer for key B and produce a locally-"valid" signature
104/// the chain then rejects.  Errors if `body` is shorter than the wire header.
105pub fn build_transaction_signing_message(body: &[u8]) -> Result<SigningMessage, SignError> {
106    if body.len() < TXN_HEADER_SZ {
107        return Err(SignError::Backend(format!(
108            "transaction body {} bytes is shorter than the {}-byte header",
109            body.len(),
110            TXN_HEADER_SZ
111        )));
112    }
113    let mut expected_pubkey = [0u8; 32];
114    expected_pubkey.copy_from_slice(&body[TXN_FEE_PAYER_OFFSET..TXN_FEE_PAYER_OFFSET + 32]);
115    Ok(SigningMessage {
116        m: tn_signature::signing_message(SignatureDomain::Transaction, body),
117        expected_pubkey,
118        body: body.to_vec(),
119    })
120}
121
122/// Verify `sig` (produced by an external signer) against the frozen message under
123/// the strict/canonical policy, then return the complete signed transaction wire
124/// (`body ‖ sig`).  Fails closed.  The returned buffer is freshly assembled from
125/// the body snapshot, so a later mutation of the caller's original body cannot
126/// desync the attached signature.  The trailing 64 bytes are the signature.
127pub fn attach_signature(msg: &SigningMessage, sig: [u8; 64]) -> Result<Vec<u8>, SignError> {
128    tn_signature::verify_message(&msg.m, &sig, &msg.expected_pubkey)
129        .map_err(|_| SignError::InvalidSignature)?;
130    let mut signed = Vec::with_capacity(msg.body.len() + 64);
131    signed.extend_from_slice(&msg.body);
132    signed.extend_from_slice(&sig);
133    Ok(signed)
134}
135
136/// Kind of EOA authorization (`tn_eoa_create_v1` / `tn_eoa_delete_v1` domain).
137#[derive(Clone, Copy, Debug, PartialEq, Eq)]
138pub enum EoaAuthKind {
139    /// Authorize creating the EOA (`tsys_account_create_eoa`).
140    Create,
141    /// Authorize deleting the EOA (`tsys_account_delete`).
142    Delete,
143}
144
145impl EoaAuthKind {
146    /// The signature domain this authorization is signed under.
147    pub fn domain(self) -> SignatureDomain {
148        match self {
149            EoaAuthKind::Create => SignatureDomain::EoaCreate,
150            EoaAuthKind::Delete => SignatureDomain::EoaDelete,
151        }
152    }
153}
154
155/// Build the canonical 82-byte EOA authorization message
156/// `DST ‖ chain_id LE ‖ fee_payer ‖ account` for `kind`.  Byte-identical to
157/// [`build_eoa_create_message`] / [`build_eoa_delete_message`].
158pub fn build_eoa_auth_message(
159    kind: EoaAuthKind,
160    chain_id: u16,
161    fee_payer: &TnPubkey,
162    account: &TnPubkey,
163) -> Vec<u8> {
164    match kind {
165        EoaAuthKind::Create => build_eoa_create_message(chain_id, fee_payer, account).to_vec(),
166        EoaAuthKind::Delete => build_eoa_delete_message(chain_id, fee_payer, account).to_vec(),
167    }
168}
169
170/// An Ed25519 signer over an opaque `SigningMessage`.  Implementations must sign
171/// `msg.as_bytes()` with standard RFC-8032 Ed25519 and return the raw 64 bytes.
172///
173/// Only [`Signer::public_key`] and [`Signer::sign`] are required.  The other
174/// methods take *semantic* inputs so a hardware signer can show the user what
175/// is being signed and build the domain-separated message itself:
176///
177/// * [`Signer::sign_transaction_body`] has a default that builds the
178///   `SigningMessage` and calls [`Signer::sign`]; a hardware signer overrides
179///   it to stream the body to the device.
180/// * [`Signer::sign_message`] and [`Signer::sign_eoa_auth`] default to
181///   [`SignError::Unsupported`]; key-holding signers implement them.
182///
183/// Callers should go through the `*_with` helpers ([`sign_transaction_body_with`],
184/// [`sign_message_with`], [`sign_eoa_auth_with`]), which verify the returned
185/// signature strictly before it is used.
186pub trait Signer {
187    /// The 32-byte public key (== the Thru address) this signer produces.
188    fn public_key(&self) -> [u8; 32];
189    fn sign(&self, msg: &SigningMessage) -> Result<[u8; 64], SignError>;
190
191    /// Sign a full transaction body (the wire bytes preceding the trailing
192    /// signature) under the `tn_txn_sign_v1__` domain.  The default builds the
193    /// 48-byte `SigningMessage` and calls [`Signer::sign`].
194    fn sign_transaction_body(&self, body: &[u8]) -> Result<[u8; 64], SignError> {
195        let msg = build_transaction_signing_message(body)?;
196        self.sign(&msg)
197    }
198
199    /// Sign an off-chain user message under the `tn_msg_sign_v1__` domain
200    /// (`M = DST_MSG ‖ message`).  `message` is the raw user message, never a
201    /// pre-built `M`.
202    fn sign_message(&self, message: &[u8]) -> Result<[u8; 64], SignError> {
203        let _ = message;
204        Err(SignError::Unsupported("message signing".into()))
205    }
206
207    /// Sign an EOA create/delete authorization for `account` (which must be
208    /// this signer's own public key): `M = DST_kind ‖ chain_id LE ‖ fee_payer ‖
209    /// account` (82 bytes).
210    fn sign_eoa_auth(
211        &self,
212        kind: EoaAuthKind,
213        chain_id: u16,
214        fee_payer: &TnPubkey,
215        account: &TnPubkey,
216    ) -> Result<[u8; 64], SignError> {
217        let _ = (kind, chain_id, fee_payer, account);
218        Err(SignError::Unsupported("EOA authorization signing".into()))
219    }
220
221    /// Whether this signer can produce signatures under the legacy
222    /// (pre-RFC-8032, in-hash domain) scheme of [`crate::tn_signature_legacy`].
223    /// Hardware signers return `false` (decision D11): a client configured for
224    /// a legacy-scheme network must refuse with a clear error before involving
225    /// the device.  Only key-holding software signers can return `true`.
226    fn supports_legacy_scheme(&self) -> bool {
227        false
228    }
229}
230
231/// A shared signer signs exactly as the signer it shares (every method,
232/// including overridden defaults, forwards to `T`).
233impl<T: Signer + ?Sized> Signer for std::sync::Arc<T> {
234    fn public_key(&self) -> [u8; 32] {
235        (**self).public_key()
236    }
237    fn sign(&self, msg: &SigningMessage) -> Result<[u8; 64], SignError> {
238        (**self).sign(msg)
239    }
240    fn sign_transaction_body(&self, body: &[u8]) -> Result<[u8; 64], SignError> {
241        (**self).sign_transaction_body(body)
242    }
243    fn sign_message(&self, message: &[u8]) -> Result<[u8; 64], SignError> {
244        (**self).sign_message(message)
245    }
246    fn sign_eoa_auth(
247        &self,
248        kind: EoaAuthKind,
249        chain_id: u16,
250        fee_payer: &TnPubkey,
251        account: &TnPubkey,
252    ) -> Result<[u8; 64], SignError> {
253        (**self).sign_eoa_auth(kind, chain_id, fee_payer, account)
254    }
255    fn supports_legacy_scheme(&self) -> bool {
256        (**self).supports_legacy_scheme()
257    }
258}
259
260/// Fail fast, before a potentially slow (hardware / remote) sign, if the
261/// signer's key is not the one the signature must verify under.
262fn check_key(signer_pk: [u8; 32], expected: &[u8; 32]) -> Result<(), SignError> {
263    if signer_pk != *expected {
264        return Err(SignError::KeyMismatch {
265            expected: *expected,
266            got: signer_pk,
267        });
268    }
269    Ok(())
270}
271
272/// Sign a message with any `Signer`: a fail-fast expected-key check *before* the
273/// (potentially slow) sign, then verify-before-attach.  Returns the complete
274/// signed transaction wire (`body ‖ sig`).
275pub fn sign_with(signer: &dyn Signer, msg: &SigningMessage) -> Result<Vec<u8>, SignError> {
276    check_key(signer.public_key(), msg.expected_pubkey())?;
277    let sig = signer.sign(msg)?;
278    attach_signature(msg, sig)
279}
280
281/// Sign a transaction body with any `Signer` via
282/// [`Signer::sign_transaction_body`]: fail-fast check that the signer's key is
283/// the body's fee payer, then verify-before-attach.  Returns the complete
284/// signed transaction wire (`body ‖ sig`); the trailing 64 bytes are the
285/// signature.
286pub fn sign_transaction_body_with<S: Signer + ?Sized>(
287    signer: &S,
288    body: &[u8],
289) -> Result<Vec<u8>, SignError> {
290    let msg = build_transaction_signing_message(body)?;
291    check_key(signer.public_key(), msg.expected_pubkey())?;
292    let sig = signer.sign_transaction_body(msg.body())?;
293    attach_signature(&msg, sig)
294}
295
296/// Sign an off-chain message with any `Signer` via [`Signer::sign_message`],
297/// then verify the signature strictly under the signer's public key.  Rejects
298/// messages larger than [`MAX_MESSAGE_SZ`].
299pub fn sign_message_with<S: Signer + ?Sized>(
300    signer: &S,
301    message: &[u8],
302) -> Result<[u8; 64], SignError> {
303    if message.len() > MAX_MESSAGE_SZ {
304        return Err(SignError::Backend(format!(
305            "message {} bytes exceeds the {}-byte limit",
306            message.len(),
307            MAX_MESSAGE_SZ
308        )));
309    }
310    let pk = signer.public_key();
311    let sig = signer.sign_message(message)?;
312    tn_signature::verify_wallet_message(message, &sig, &pk)
313        .map_err(|_| SignError::InvalidSignature)?;
314    Ok(sig)
315}
316
317/// Sign an EOA create/delete authorization with any `Signer` via
318/// [`Signer::sign_eoa_auth`]: fail-fast check that `account` is the signer's
319/// own key (the runtime verifies the signature under `account`), then verify
320/// the signature strictly over the canonical 82-byte message.
321pub fn sign_eoa_auth_with<S: Signer + ?Sized>(
322    signer: &S,
323    kind: EoaAuthKind,
324    chain_id: u16,
325    fee_payer: &TnPubkey,
326    account: &TnPubkey,
327) -> Result<[u8; 64], SignError> {
328    check_key(signer.public_key(), account)?;
329    let sig = signer.sign_eoa_auth(kind, chain_id, fee_payer, account)?;
330    let m = build_eoa_auth_message(kind, chain_id, fee_payer, account);
331    tn_signature::verify_message(&m, &sig, account).map_err(|_| SignError::InvalidSignature)?;
332    Ok(sig)
333}
334
335/// A local, key-holding `Signer` — the control implementation for tests / CLI /
336/// native use.  Holds a raw seed, so it belongs in a key-holding package, never a
337/// key-free / browser-safe core.
338pub struct LocalSigner {
339    signing_key: SigningKey,
340}
341
342impl LocalSigner {
343    pub fn from_seed(seed: [u8; 32]) -> Self {
344        Self {
345            signing_key: SigningKey::from_bytes(&seed),
346        }
347    }
348}
349
350impl Signer for LocalSigner {
351    fn public_key(&self) -> [u8; 32] {
352        self.signing_key.verifying_key().to_bytes()
353    }
354    fn sign(&self, msg: &SigningMessage) -> Result<[u8; 64], SignError> {
355        // standard RFC-8032 over the exact frozen bytes
356        Ok(self.signing_key.sign(msg.as_bytes()).to_bytes())
357    }
358    fn sign_message(&self, message: &[u8]) -> Result<[u8; 64], SignError> {
359        let m = tn_signature::signing_message(SignatureDomain::Msg, message);
360        Ok(self.signing_key.sign(&m).to_bytes())
361    }
362    fn sign_eoa_auth(
363        &self,
364        kind: EoaAuthKind,
365        chain_id: u16,
366        fee_payer: &TnPubkey,
367        account: &TnPubkey,
368    ) -> Result<[u8; 64], SignError> {
369        // The runtime verifies the authorization under `account`, so only the
370        // account's own key may sign it.
371        check_key(self.public_key(), account)?;
372        let m = build_eoa_auth_message(kind, chain_id, fee_payer, account);
373        Ok(self.signing_key.sign(&m).to_bytes())
374    }
375    /// A local signer holds the raw seed, so it can also sign under the legacy
376    /// scheme (`tn_signature_legacy`).
377    fn supports_legacy_scheme(&self) -> bool {
378        true
379    }
380}
381
382#[cfg(test)]
383mod tests {
384    use super::*;
385
386    /// A minimal transaction body (>= header length) whose fee-payer field
387    /// (offset 48) holds `pk`.
388    fn body_with_fee_payer(pk: &[u8; 32]) -> Vec<u8> {
389        let mut body = vec![0u8; TXN_HEADER_SZ + 8];
390        body[TXN_FEE_PAYER_OFFSET..TXN_FEE_PAYER_OFFSET + 32].copy_from_slice(pk);
391        body
392    }
393
394    #[test]
395    fn local_signer_round_trip_produces_a_valid_signed_wire() {
396        let s = LocalSigner::from_seed([7u8; 32]);
397        let pk = s.public_key();
398        let body = body_with_fee_payer(&pk);
399        let msg = build_transaction_signing_message(&body).unwrap();
400        assert_eq!(msg.as_bytes().len(), 48, "M = DST_TXN ‖ SHA-256(body)");
401        assert_eq!(
402            msg.expected_pubkey(),
403            &pk,
404            "expected key is the body's fee-payer"
405        );
406        let signed = sign_with(&s, &msg).unwrap();
407        // signed = body ‖ sig; the trailing 64 bytes verify as a txn signature.
408        assert_eq!(signed.len(), body.len() + 64);
409        assert_eq!(&signed[..body.len()], &body[..]);
410        let sig: [u8; 64] = signed[body.len()..].try_into().unwrap();
411        assert!(crate::tn_signature::verify_transaction(&body, &sig, &pk).is_ok());
412    }
413
414    #[test]
415    fn key_mismatch_is_fail_fast() {
416        // The body names fee-payer all-2s, but the signer holds a different key.
417        let s = LocalSigner::from_seed([1u8; 32]);
418        let body = body_with_fee_payer(&[2u8; 32]);
419        let msg = build_transaction_signing_message(&body).unwrap();
420        assert!(matches!(
421            sign_with(&s, &msg),
422            Err(SignError::KeyMismatch { .. })
423        ));
424    }
425
426    #[test]
427    fn attach_rejects_tampered_signature() {
428        let s = LocalSigner::from_seed([3u8; 32]);
429        let pk = s.public_key();
430        let body = body_with_fee_payer(&pk);
431        let msg = build_transaction_signing_message(&body).unwrap();
432        let mut sig = s.sign(&msg).unwrap();
433        sig[40] ^= 1;
434        assert!(attach_signature(&msg, sig).is_err());
435    }
436
437    #[test]
438    fn short_body_is_rejected() {
439        assert!(build_transaction_signing_message(b"too short").is_err());
440    }
441
442    #[test]
443    fn sign_transaction_body_default_matches_sign_over_m() {
444        let s = LocalSigner::from_seed([9u8; 32]);
445        let body = body_with_fee_payer(&s.public_key());
446        let msg = build_transaction_signing_message(&body).unwrap();
447        assert_eq!(
448            s.sign_transaction_body(&body).unwrap(),
449            s.sign(&msg).unwrap()
450        );
451        let signed = sign_transaction_body_with(&s, &body).unwrap();
452        assert_eq!(signed, sign_with(&s, &msg).unwrap());
453    }
454
455    #[test]
456    fn sign_transaction_body_with_is_fail_fast_on_key_mismatch() {
457        let s = LocalSigner::from_seed([1u8; 32]);
458        let body = body_with_fee_payer(&[2u8; 32]);
459        assert!(matches!(
460            sign_transaction_body_with(&s, &body),
461            Err(SignError::KeyMismatch { .. })
462        ));
463    }
464
465    /// A signer that returns garbage from `sign_transaction_body` (like a
466    /// misbehaving device) is caught by verify-before-attach.
467    struct GarbageSigner([u8; 32]);
468    impl Signer for GarbageSigner {
469        fn public_key(&self) -> [u8; 32] {
470            self.0
471        }
472        fn sign(&self, _msg: &SigningMessage) -> Result<[u8; 64], SignError> {
473            Ok([0x11u8; 64])
474        }
475    }
476
477    #[test]
478    fn sign_transaction_body_with_rejects_bad_signature() {
479        let pk = LocalSigner::from_seed([4u8; 32]).public_key();
480        let body = body_with_fee_payer(&pk);
481        assert!(matches!(
482            sign_transaction_body_with(&GarbageSigner(pk), &body),
483            Err(SignError::InvalidSignature)
484        ));
485    }
486
487    #[test]
488    fn default_semantic_methods_are_unsupported() {
489        let g = GarbageSigner([0u8; 32]);
490        assert!(matches!(
491            g.sign_message(b"hi"),
492            Err(SignError::Unsupported(_))
493        ));
494        assert!(matches!(
495            g.sign_eoa_auth(EoaAuthKind::Create, 1, &[1u8; 32], &[0u8; 32]),
496            Err(SignError::Unsupported(_))
497        ));
498        assert!(!g.supports_legacy_scheme());
499    }
500
501    #[test]
502    fn local_sign_message_matches_tn_signature() {
503        let seed = [5u8; 32];
504        let s = LocalSigner::from_seed(seed);
505        let pk = s.public_key();
506        let msg = b"hello thru";
507        let sig = sign_message_with(&s, msg).unwrap();
508        assert_eq!(sig, tn_signature::sign_message(msg, &pk, &seed).unwrap());
509        assert!(tn_signature::verify_wallet_message(msg, &sig, &pk).is_ok());
510    }
511
512    #[test]
513    fn sign_message_with_enforces_size_limit() {
514        let s = LocalSigner::from_seed([5u8; 32]);
515        assert!(sign_message_with(&s, &vec![0u8; MAX_MESSAGE_SZ]).is_ok());
516        assert!(sign_message_with(&s, &vec![0u8; MAX_MESSAGE_SZ + 1]).is_err());
517    }
518
519    #[test]
520    fn local_sign_eoa_auth_matches_existing_builders() {
521        let seed = [6u8; 32];
522        let s = LocalSigner::from_seed(seed);
523        let pk = s.public_key();
524        let fee_payer = [8u8; 32];
525        let create = sign_eoa_auth_with(&s, EoaAuthKind::Create, 2, &fee_payer, &pk).unwrap();
526        assert_eq!(
527            create,
528            crate::txn_tools::bp_sign_eoa_creation(&seed, 2, &fee_payer, &pk)
529        );
530        let delete = sign_eoa_auth_with(&s, EoaAuthKind::Delete, 2, &fee_payer, &pk).unwrap();
531        let sk = SigningKey::from_bytes(&seed);
532        assert_eq!(
533            delete,
534            sk.sign(&build_eoa_delete_message(2, &fee_payer, &pk))
535                .to_bytes()
536        );
537        // The domain tag in the built message is the domain's DST.
538        for kind in [EoaAuthKind::Create, EoaAuthKind::Delete] {
539            let m = build_eoa_auth_message(kind, 2, &fee_payer, &pk);
540            assert_eq!(m.len(), 82);
541            assert_eq!(&m[..16], kind.domain().dst());
542        }
543        assert_ne!(create, delete);
544    }
545
546    #[test]
547    fn sign_eoa_auth_rejects_foreign_account() {
548        let s = LocalSigner::from_seed([6u8; 32]);
549        assert!(matches!(
550            sign_eoa_auth_with(&s, EoaAuthKind::Create, 1, &[8u8; 32], &[7u8; 32]),
551            Err(SignError::KeyMismatch { .. })
552        ));
553        assert!(matches!(
554            s.sign_eoa_auth(EoaAuthKind::Delete, 1, &[8u8; 32], &[7u8; 32]),
555            Err(SignError::KeyMismatch { .. })
556        ));
557    }
558}