Skip to content

Latest commit

 

History

History
267 lines (181 loc) · 60.5 KB

security-model.md

File metadata and controls

267 lines (181 loc) · 60.5 KB
title Security model
description What hardhat-kms guarantees when a cloud KMS key signs, what it leaves to your cloud's access control, and what happens when a KMS call times out.

Security model

Audience: users who hold funds or contract roles at a KMS key's address and want to know what the plugin guarantees, what it leaves to them, and what can still go wrong. Assumes you have read How hardhat-kms works or know the path of a request.

The plugin never holds a private key: the KMS signs and the plugin checks. Its job is to make sure that what the KMS signs is what you asked for, for the chain you meant, with the key you configured, and that nothing leaks on the way. Who may use the key at all is for your cloud provider's access control to decide, not the plugin.

What the plugin protects against

Risk What the plugin does
A script or dependency gets your key to sign a hash it built, such as another transaction No RPC method signs a 32-byte digest the caller supplies. Over RPC, the plugin signs only transactions it filled itself, EIP-191 messages and EIP-712 typed data. See No bare digests over RPC. A rawSign account signs one only for a key with allowRawDigests: true in the config. kms sign --no-hash asks at a terminal, and without one signs only for such a key with --yes (Raw digests and EIP-7702).
A script, dependency or agent gets the key to delegate its account to a contract With allowedDelegates on the key, the plugin refuses an EIP-7702 authorization to any contract the list does not allow on that chain, before the KMS signs. See EIP-7702 delegates.
A signature made for one chain is used on another Each connection checks the node's chain id. Every transaction carries an explicit chainId that must match it, and typed data that names a chain must match it too. See Typed data checks its chain.
The key changes underneath you: a rotation, or an alias that now points at another key Core, every provider: your address pin is checked before the first signature, in every run. Built-in providers only: AWS keys sign with the key ARN, not the alias, and Google Cloud and Azure keys sign with a pinned key version. That pinning lasts only while a signer is open: signers close 5 s after the last connection closes, and the next use, or the next run, resolves the alias or the current version again. Only the address pin protects across runs.
The KMS or an adapter returns a malformed signature, or one from another key Core, every provider: every signature is verified against the key before use. See Every signature is verified. Built-in Azure adapter only: the adapter refuses a Key Vault response whose kid names another vault or key, and a sign response whose kid names another version than the pinned one.
The private key can leave the KMS Built-in Azure adapter only: the adapter refuses a Key Vault or Managed HSM key that is exportable or has a release policy, before it signs anything, because Key Vault's release operation can hand such a key's private key to an environment the policy accepts.
The digest or signature is corrupted between the plugin and Google Cloud KMS Built-in Google Cloud adapter only: CRC32C checksums in both directions. A mismatch is retried at most three times, then fails.
Credentials or key ids leak through errors and logs See No secrets in errors, logs or task output.
A client retries a send and the transaction goes out twice A send whose broadcast gets no answer fails with code -32000 and the transaction hash. If the same request comes back on the same connection within 120 s, the plugin usually sends the same signed bytes again; if that nonce has since been used and the node does not know the transaction, it signs a new one. See Transactions from one account go out in order.

Guarantees

The plugin's core enforces the first four guarantees below, outside the adapter, so they hold for third-party providers as well as the built-in ones. Signature verification runs after the adapter answers; the digest rule, the typed-data chain check and the send lock run before any adapter call.

Every signature is verified

No signature leaves the plugin unless it recovers to the account's address. The signer parses each signature strictly, checks the range of r and s, folds s to its low form, finds the recovery bit by trying each candidate against the public key it already knows, and verifies the result. Messages and typed data are checked once more with an EIP-191 or EIP-712 verifier, and a transaction must recover to its from before it is sent. A signature that fails one of the signer's own checks (parse, range, recovery and verification against the key) gets one fresh attempt, then an error. A failure of the final EIP-191 or EIP-712 verification, or of the sender check, fails at once.

For the same request, the plugin encodes the same payload and signs the same digest as a local signer with the same key, such as viem's privateKeyToAccount, and its signature recovers to the same address. The bytes can differ. viem and Hardhat's local accounts derive the ECDSA random value k from the key and the digest (RFC 6979), so they return the same signature every time. AWS KMS picks a random k for each signature (AWS Database Blog), so two signatures of one digest differ. Google Cloud KMS and Azure Key Vault do not document how they choose k. On 2026-10-07, two signatures of one digest from a Google Cloud key and from an Azure key differed, as they did on AWS. That is an observation, not a documented behaviour, so do not rely on it either way. Check a signature by the address it recovers to, not by comparing its bytes with another signature. A retried send is the exception: the plugin usually resends the signed transaction it kept (Transactions from one account go out in order).

No bare digests over RPC

No JSON-RPC method accepts a bare digest. eth_sign and personal_sign both add the EIP-191 prefix, as Hardhat does. Explicit raw signing is available through the task (kms sign --no-hash), from the CLI or from code, or a library account (getAccount(address, { rawSign: true })). Either route signs any 32 bytes it is given, and those can be the hash of a transaction, a permit for any chain, or an EIP-7702 authorization: sign only a digest you computed yourself. The next section says when each route signs. A tool that expects raw-digest signing over RPC does not work with a KMS account, by design.

Raw digests and EIP-7702

An EIP-7702 authorization is signed over keccak256(0x05 || rlp([chainId, address, nonce])), a 32-byte digest like any other. A raw-digest signature of that hash is a valid authorization: it delegates the account to the code at address, which then acts for the account until another authorization replaces it. kms sign-auth and the library account's signAuthorization check the chain and show the delegate; a raw digest gets none of those checks, since a hash cannot be reversed. An agent driven by injected text has signed such an authorization to drainer code without the key ever leaving it (mangrove-agent incident).

So raw digests need a person or an opt-in on the key:

  • kms sign --no-hash asks at a terminal before any sign request, default no. Without a terminal it signs only for a key with allowRawDigests: true and with --yes, and refuses otherwise. A key from --kms has no config, so only a person at a terminal can approve its raw digests.
  • getAccount(address, { rawSign: true }) works only for a key with allowRawDigests: true, and prints a warning each time it makes such an account.

The opt-in makes raw signing a property of the key that a reviewer sees in the config. It is not a barrier against code in the same process, which can edit the config at any time, before or after Hardhat loads it (the plugin freezes each resolved key, but code can replace the config's kms section or a network's kmsAccounts), or call the cloud SDK with the same credentials. For a key with the opt-in, the opt-in is the only check between such code and a signed authorization.

The question stops callers that have no terminal: CI, a script with piped or closed input, an agent that runs commands without one. It does not prove that a person answered. A program that drives a pseudo-terminal, such as script or an agent harness that allocates one, passes the terminal check and can type y, and code in the same process can feed the question's input. For a key that holds funds or roles, the controls that hold are allowRawDigests left off, so the library account never gets sign, and the cloud's or Turnkey's policy on the key.

Where the check runs depends on the provider:

  • AWS KMS, Google Cloud KMS and Azure Key Vault see only the 32-byte digest, the same for a transaction, a permit or an authorization. No IAM or RBAC policy can tell them apart, so the plugin's question and opt-in are the only check.
  • Turnkey receives raw digests and EIP-7702 authorizations from the plugin the same way: sign_raw_payload with HASH_FUNCTION_NO_OP and PAYLOAD_ENCODING_HEXADECIMAL. A Turnkey policy on authorizations, such as one on eth.eip_7702_authorization, binds only if the API user's policies also deny that NO_OP and HEXADECIMAL combination; any grant of it lets the key sign any digest, an authorization included. Deny it for every key that does not need raw digests, authorizations or transactionSigning: "digest" (Turnkey setup).

Typed data checks its chain

When typed data names a chain in domain.chainId, it must equal the connection's chain, read with eth_chainId, or the request fails before any sign request. (For a key without an address pin, the first request may still read the key's public key.) chainId: 0 is checked like any other value. kms.allowCrossChainTypedData: true turns the check off. Typed data without domain.chainId is signed, as Hardhat, Foundry and MetaMask sign it, and its signature is valid on every chain. The kms sign --data task runs the same check against --chain, else the --network config's chainId, else that network's eth_chainId; without --chain or --network, typed data that names a chain is refused. --allow-cross-chain turns the check off for one run.

Transactions from one account go out in order

The send lock runs sends from one KMS address on one chain one after the other, across every connection in the process. The nonces the plugin has used are remembered per connection, so a send on a second connection to the same chain can get a nonce the first already used when the node's pending count lags. When the plugin looks up a transaction whose broadcast got no answer and the lookup fails, the transaction counts as "not known", so the next send can reuse its nonce. A library account's transactions that viem sends through the connection take their turn too, from the nonce to the broadcast; a viem client with its own transport only reserves its nonce (Library accounts).

Each request reaches the node's eth_sendRawTransaction at most once, and a request never signs again after its broadcast. When a broadcast gets no answer, the plugin keeps the signed bytes for 120 s. A retry of the identical request usually resends them, with the same hash and nonce; if that nonce has since been used and the node does not know the transaction, the plugin signs a new one. A retry is also signed afresh when it comes on another connection (the cache is per connection), when its params cannot be used as a cache key (a Date or a Map, for example), or after a later send asked the node about the first transaction and the node did not have it. Which nonce a send gets and Failed broadcasts in the RPC methods reference give the rules, and Recover from an uncertain transaction send the steps to check and repair a nonce.

No secrets in errors, logs or task output

The built-in providers never read credentials from the Hardhat config. AWS and Google Cloud use their SDK's default credential chain; Azure uses the plugin's own chain (Credentials). The plugin's errors are built from a short list of fields (provider, operation, key display id, the SDK error's class name or code, HTTP status, request id) and never wrap the SDK's own error, which can carry request headers. The debug output never contains configuration variable values, credentials or a provider's error messages. A test plants secrets in configuration variables, in a third-party key's token and in a provider's error message, and fails if any of them reaches the output.

Google's client libraries keep their own logs, which the plugin does not control. With GOOGLE_SDK_NODE_LOGGING set to kms, auth, *, all or, from google-logging-utils 2.1.0, true, they print every Cloud KMS request and response with the full key version name, and google-auth-library prints the access token of each token refresh. The plugin warns once on standard error when the variable turns those logs on, and leaves it as it is. Unset it outside a local debugging session; see Google Cloud's own logs.

A key id read from a configuration variable shows as the variable's name, such as aws:<AWS_KMS_KEY_ID>, in errors, debug output and task output. A literal id written in the config prints as written; only ids from variables are masked. kms accounts --show-ids shows the variables' values too, after a warning on standard error. See the tasks reference.

What the plugin does not protect against

  • Access to the key. Anyone or anything with permission to sign with the key in your cloud account can sign anything with it, without the plugin. Your provider's IAM or RBAC decides that. The setup guides give the minimal permissions for AWS, Google Cloud, Azure and Turnkey.
  • Code in the same process. Any script, test, plugin or dependency that runs in your Hardhat process can send requests to the connection and get your KMS accounts to sign transactions, messages and typed data, as it could with Hardhat's local accounts. It can also run the plugin's tasks from code: kms sign --no-hash --yes signs any digest with a key that sets allowRawDigests: true, kms sign-tx signs transactions without sending them, and kms sign-auth with yes signs an EIP-7702 authorization without a question for a delegate in the key's allowedDelegates or the zero address, which hands that contract control of the account until another authorization replaces it; with force it signs one for chain 0, valid on every chain. A key with allowedDelegates limits kms sign-auth and signAuthorization to the contracts listed, but code in the process can get around the list (EIP-7702 delegates). It can also call connection.kms.getAccount(address, { rawSign: true }) for such a key and sign any digest with the account's sign, and it can change the config before Hardhat loads it. A third-party provider package is code in the same process too: it reads its key's config, including any credentials there, and the error messages it raises reach you unchanged. Run only code you trust in a process that has access to a key that holds funds.
  • Cross-chain replay of messages and chainless typed data. personal_sign and eth_sign signatures carry no chain, and neither does typed data without domain.chainId. Such a signature is valid on every chain; the contract that checks it must bind it to a chain itself.
  • Nonce collisions between processes, and between connections against a lagging node. The send lock covers one Hardhat process, and the plugin's memory of used nonces covers one connection. Two processes sending from the same key at the same time can choose the same nonce, and so can two connections in one process when the node's pending count lags; one transaction then replaces or blocks the other. See Parallel sends and failed broadcasts.
  • Key deletion and lockout. If the key is deleted, or nobody can reach it any more, the funds and roles at its address are lost for good: nobody holds a copy of the private key. Prevent and recover from losing a key covers each provider's waiting period, the undo paths, lockout and backups.
  • The KMS service and the machine running Hardhat. The plugin trusts the provider's service to keep the key, and the machine's credentials to be yours. SECURITY.md lists these as out of scope.

Official packages

The official packages are hardhat-kms and the packages under the @hardhat-kms npm scope. A package with any other name, such as hardhat-kms-aws, does not come from this project.

Only members of the hardhat-kms npm organization can publish under @hardhat-kms/, but anyone can publish an unscoped name that looks like this project's. A provider package runs inside your Hardhat process with the same access as the rest of your code. It can read your environment and cloud credentials, and sign with any key those credentials allow. Check the name before you install. A third-party provider is published under its own name or scope; review it as you would any dependency that runs with your cloud credentials.

What you configure

The plugin's checks work best with these settings:

Setting Why
Least-privilege access Grant the identity that runs Hardhat only what signing needs, as the setup guides for AWS, Google Cloud, Azure and Turnkey show. On Turnkey, use a non-root API user, and deny it credential changes, which Turnkey otherwise allows a user on its own credentials: a root user's key bypasses every policy. On AWS, the policy's kms:SigningAlgorithm and kms:MessageType conditions limit kms:Sign to what the plugin sends.
An address pin on each key The plugin refuses to sign if the key no longer derives to that address, for example after an alias was moved. Get the address with npx hardhat kms accounts. See the configuration reference and Rotate a key and pin its address.
chainId on each http network The plugin then also checks the node's eth_chainId against your config, so a wrong RPC URL fails before a transaction or chain-bound typed data is signed. Messages do not read the chain.
timeoutMs The time each KMS call may take, 30 s by default, set in kms.defaults or per key. Read the next section before you lower it.
allowedDelegates on each key List the contracts the key may delegate its account to with EIP-7702, per chain. An empty list allows only revocation. See EIP-7702 delegates.
kms.allowCrossChainTypedData Leave it false, the default, unless you sign typed data for another chain on purpose.

EIP-7702 delegates

An EIP-7702 authorization lets the code at its delegate act for the account until another authorization replaces it. A key's allowedDelegates lists the contracts it may delegate to, per chain, optionally pinned to a code hash. The plugin checks the list before the KMS signs, in kms sign-auth, a library account's signAuthorization (which the Alchemy Wallet APIs use), and the self-authorizations of a transaction (eth_sendTransaction, eth_signTransaction, kms sign-tx, a library account's signTransaction). No flag overrides it. The zero address, which clears a delegation, always passes. The list is off until you set it.

What it protects against: mistakes, and agents or scripts that use the configured key names. A misconfigured script, an address copied from another chain, or an agent or a prompt injection that runs kms sign-auth or calls signAuthorization with a configured key: each fails on a delegate that is not listed. It is not a barrier against code written to get around it, which runs in the same process (below). A codeHash also catches an address whose code is not what you reviewed on that chain.

What it does not protect against:

  • A leaked key or cloud credential. Whoever holds them signs without the plugin. Most malicious delegations in the first weeks after Pectra went this way: Wintermute found that most delegations then pointed at the same sweeper code, set on wallets whose keys had already leaked (Wintermute, CoinDesk, 2025-06-02). Your cloud's access control is the defence there.
  • Batch phishing through a listed delegate. The delegate is legitimate; the harm is in the calls the account then makes through it, which the list does not see (ScamSniffer, 2025-05-24; 2025-08-22).
  • Raw digests. kms sign --no-hash and a rawSign account sign any 32 bytes, which can be an authorization's hash; the plugin cannot tell. Raw digests and EIP-7702 covers how they are gated.
  • Tuples signed by other accounts, which a KMS sender's transaction may carry. They delegate those accounts, not the key's.
  • Keys from --kms, which have no config and so no list. kms sign-auth and connections refuse a --kms key that is the same KMS key as a config key with allowedDelegates, in kms.keys or any network's kmsAccounts, when it would sign an authorization to a delegate other than the zero address, and kms sign-tx refuses it for any transaction with an authorizationList. They match by the config key's address pin, or by key id or alias for a config key without one (how keys are matched). An AWS key id or alias matches whatever region, profile or endpoint either key sets, so the same alias in another region is refused too. A connection refuses a --kms key that a network's kmsAccounts already lists, or that has the same address as one of them. A --kms key that names the KMS key another way, such as a key ARN or key id for an alias, and matches no pin, is not caught. A Google Cloud key written with the project number in one place and the project id in the other is not caught either. Pin the config key's address to catch them.
  • Whoever can edit the Hardhat config, which can widen the list, and code in the same process. Two config keys for the same KMS key, one with a list and one without, are not linked: the key without a list signs any delegate. The plugin freezes each resolved key and its list, so a list cannot be widened in place, but such code can replace the config's kms section or a network's kmsAccounts, edit the config before Hardhat loads it, or call the cloud SDK with the same credentials.
  • A lying node. A codeHash is checked against what the network's node returns for eth_getCode. A node that lies can pass other code. For a chain-0 authorization the code is read on the connection's chain only, and the plugin says so: the same address can hold other code on another chain. kms sign-auth --chain reads no node, so it refuses a delegate whose entry has a codeHash.
  • A delegate that is a proxy. A codeHash pins the proxy's own code, not the implementation it points to, which its admin can change after you sign.

Other signers limit delegates the same way:

Signer How it limits delegates
Ledger Ethereum app A built-in list of delegates, each for one chain or for all chains. A delegate not on it is refused, except the zero address. A chain-0 authorization matches only an entry for all chains; app 1.22.4 fixed a bug where it also matched chain-specific entries (whitelist_7702.c, CHANGELOG).
Trezor firmware A built-in list of delegates per chain. An unknown delegate fails with "Unknown EIP-7702 delegate address", and chain 0 is refused (sign_tx_eip1559.py, sc_constants.py).
MetaMask Offers dapps no method to sign an authorization: it upgrades the account itself when a dapp asks for batched calls. Its Smart Accounts Kit says its EIP-7702 path "doesn't work with a JSON-RPC Account like MetaMask" (batch transactions, Smart Accounts Kit).
Privy policies A policy rule on eth_sign7702Authorization can limit the contract field of ethereum_7702_authorization to a list (Ethereum policy examples).
Turnkey policies A policy condition on eth.eip_7702_authorization.address, chain_id and nonce (Ethereum policy examples). The plugin sends authorizations to Turnkey as a digest, so such a policy does not see them today (Raw digests and EIP-7702); allowedDelegates applies to Turnkey keys too.

ERC-7902 says wallets "MUST maintain a strict shortlist of well-known and publicly audited smart account implementations that are acceptable as delegation". The plugin ships no built-in list: which delegates a key needs is the project's decision. Decision 0022 records why.

The kms sign-auth question

kms sign-auth shows what an authorization does before the KMS signs, and at a terminal waits for y or yes (The question). It shows the account, the delegate with its label and checksummed address, the chain (ALL CHAINS for chain 0), the nonce against the account's nonce, the delegate's code size and hash, the account's current delegation, and that the delegation lasts until replaced, is not undone if the carrying transaction reverts, and can be submitted by anyone who holds the signature. Without a terminal the task signs only with --yes, and only for a delegate in the key's allowedDelegates or the zero address, so a key without a list, which includes every key from --kms, cannot delegate from CI. It also refuses tuples that cannot apply: a nonce the account has passed, a delegate that is itself delegated, a precompile, and an account with contract code. Decision 0023 records why.

What the question does not do:

  • It does not prove a person answered. A program that drives a pseudo-terminal passes the terminal check and can type y, and code in the same process can feed the input, edit the config, or run the task with --yes for a listed delegate. The list, not the question, is what binds such code.
  • It trusts the node. The code, the hash, the slot and the delegation come from eth_getCode and eth_getStorageAt on the --network node, and a node that lies can hide code or a delegation. The question names the network it read, and with --chain alone it reads nothing and says "not checked".
  • It covers only kms sign-auth. A library account's signAuthorization and a transaction's self-authorizations have no person to ask; the list is their check.

When a KMS call times out

A timeout ends the plugin's wait, not the KMS's work. A sign request that reached the KMS can still be signed after the plugin has given up on it. The plugin never uses such a late signature.

What the plugin does

Each KMS call runs under its own time limit, timeoutMs. When the limit passes, the plugin stops waiting and the request fails with no answer within <timeoutMs> ms. For AWS, Azure and Google Cloud, the plugin hands the limit to the SDK as an abort signal, which cancels the request on the network. Google Cloud also sets timeoutMs as each attempt's deadline; with a google-gax older than 6.15.0, which ignores the signal, an attempt already in flight can outlive the plugin's give-up by up to timeoutMs. A request already on the network can still arrive and be signed.

Whatever answer comes back late, the plugin drops it. It never returns a late signature to your script and never sends it to the node. A late answer to a key lookup cannot choose the key either: the AWS adapter keeps a key ARN, and the Azure adapter pins a key version, only from a lookup that finished in time.

The plugin does not retry a timed-out call. For a transaction, the failure comes before the broadcast, so nothing is sent and the nonce is not used: running the script again fills the same nonce. Raise timeoutMs if your KMS is slow to answer. A Turnkey key that signs with sign_transaction is the exception: Turnkey can complete the transaction itself, so the plugin keeps its nonce held (Turnkey keys).

A library account made with getAccount(address, { signal }) can also be cancelled before timeoutMs runs out. An abort works like a timeout: the plugin stops waiting, aborts the SDK call, drops any late signature and does not retry, and a request that already reached the KMS can still be signed there (Cancelling with a signal).

How many sign requests one call can send

One request to the plugin makes at most two signer calls (packages/hardhat-kms/src/internal/signer/kms-signer.ts:299-318). The second happens only when the first returned a signature that failed the signer's checks; a timeout or any other error is never retried by the signer. Each signer call can in turn send several requests to the KMS, because the provider's SDK, or the adapter, retries transient failures:

Provider Requests per signer call Worst case per request Source
AWS KMS Up to 3 attempts, the AWS SDK's default. A higher AWS_MAX_ATTEMPTS or profile max_attempts raises it. 2 x 3 = 6 DEFAULT_MAX_ATTEMPTS = 3, AWS_MAX_ATTEMPTS and max_attempts in @smithy/core 3.35.0 (submodules/retry). The plugin sets no maxAttempts: packages/hardhat-kms-aws/src/internal/adapter.ts:173-177.
Azure Key Vault Up to 4: the first request and up to 3 retries, the Azure SDK pipeline's default. 2 x 4 = 8 DEFAULT_RETRY_POLICY_COUNT = 3 in @azure/core-rest-pipeline 1.25.0 (constants.js). The plugin passes only httpClient: packages/hardhat-kms-azure/src/internal/adapter.ts:76.
Google Cloud KMS Up to 4: the first request and up to 3 retries by the adapter, only after a CRC32C mismatch or UNAVAILABLE. 2 x 4 = 8 MAX_RETRIES = 3 in packages/hardhat-kms-gcp/src/internal/adapter.ts:19; the SDK's own retries are off (retry: null, :248).

Any of these requests can reach the KMS and produce a signature the plugin never sees, before or after the plugin stops waiting.

A Turnkey key differs. The adapter sends each signer call's request up to 4 times, after no answer, a server error or a rate limit, but always with the same body, and Turnkey answers the same body with the same activity, so the retries make one signature (packages/hardhat-kms-turnkey/src/internal/client.ts). The worst case is 2 signatures: the second signer call builds a new request, which is a new activity. Each counts toward the organization's monthly signature quota.

What this means for you

  • Your provider's request counts and audit logs can show more sign requests than the signatures your script used. Each extra one is for the same digest your script asked for, never for another one.
  • If you use a third-party provider plugin that asks a person to approve each signature, an approval request can stay open after the plugin has given up on it. Approving it then signs a digest that the plugin drops, and your script has already seen an error. timeoutMs also bounds the wait for that approval: raise it on that key to cover the time a person takes to approve.
  • With AWS KMS, Google Cloud KMS, Azure Key Vault, and a Turnkey key with transactionSigning: "digest", a timeout on a send leaves no transaction behind: a late signature covers only a digest, which nobody can broadcast. Check the error, then run the script again; the plugin fills the transaction afresh.
  • A Turnkey key that signs with sign_transaction, the default, differs: a timeout, an abort or another failure after the request reached Turnkey can leave a signed transaction there. See Turnkey keys.

Turnkey keys

A Turnkey key adds five things to the model, because Turnkey decides through its own users and policies, and keeps a record of every request:

  • A root user's API key bypasses every policy. Turnkey's root quorum "can execute any action and bypass the policy engine" (Root quorum). With such a key, anyone can sign anything with any account of the organization, and export or change it. The plugin cannot tell whether an API key belongs to a root user. Configure only the key of a non-root API user, limited by policies to the requests the plugin sends. A user may change its own credentials unless a policy says otherwise, so a leaked key could add a key of its own that survives rotation; the guide's third policy denies that (Set up a Turnkey wallet account).

  • A pending activity can still sign. When a policy needs more approvals or another authenticator, the plugin fails at once with turnkey.activity.approval-needed and does not wait. The activity stays in Turnkey, since activities do not expire: if an approver approves it later, a signature exists for a request the plugin gave up on. Reject it by the activity id the error names (Reject the pending activity). For a transaction, the plugin also keeps the nonce held, as below.

  • A transaction can outlive the plugin's call. When a sign_transaction request reached Turnkey and the plugin then gives up on it, Turnkey can still complete the activity, which then holds a signed transaction that every user of the organization can read and broadcast. That happens after a timeout or an abort, an activity that needs approval, a status query that fails, an answer the plugin cannot read, or a signed transaction the plugin refused. The plugin therefore never signs that nonce again on the network connection. Only a definite refusal frees it: Turnkey refused the request (a 4xx answer), or the activity ended FAILED or REJECTED. The same goes for a transaction Turnkey signed but the node refused, for example for insufficient funds: Turnkey keeps it, and it becomes valid once the account has the funds. Its nonce stays held too, and the send fails with core.tx.refused-provider-copy, which names the nonce and the kind of refusal. A transaction the plugin broadcast and the node accepted is public anyway, so its hold ends there, even if the node drops it later. A nonce held with nothing to fill it stalls the account's later transactions; the plugin warns, and the setup guide gives the recovery. The error (core.signer.transaction-outstanding) starts with the cause and names the nonce and the activity id, and the connection's later sends from the account skip the nonce, which leaves a gap rather than two valid transactions at one nonce. Settle it before you send anything else from the account: reject the activity while it is pending, then, or if it completed, send a replacement transaction with that nonce. The hold ends once the nonce is mined, when Turnkey's copy itself reaches the node through the connection, or when the connection closes. On a local network, evm_revert or hardhat_reset can undo the mined transaction that ended it, and the plugin does not restore the hold, a known limit. A new script run starts without the hold, so it can sign the nonce again unless you settled it (When Turnkey does not answer in time). A key with transactionSigning: "digest" signs only a hash, which nobody can broadcast, so its failures hold nothing.

  • Turnkey sees and keeps what each request sends, and so do all its users. Every user of the organization can read its activities (Policies overview):

    Request What the activity holds What Turnkey's policies can match
    Transactions the unsigned transaction, then the signed one the account and the transaction's fields as eth.tx.*, such as to, chain_id and value
    Transactions of a key with transactionSigning: "digest" the 32-byte digest the account, HASH_FUNCTION_NO_OP and PAYLOAD_ENCODING_HEXADECIMAL; not eth.tx.*
    EIP-7702 authorizations, digests the 32-byte digest the account, HASH_FUNCTION_NO_OP and PAYLOAD_ENCODING_HEXADECIMAL
    Messages the EIP-191 message itself, with its prefix the account, HASH_FUNCTION_KECCAK256 and PAYLOAD_ENCODING_HEXADECIMAL; not the text
    Typed data the typed data as JSON the account, PAYLOAD_ENCODING_EIP712, and the typed data as eth.eip_712

    A message's text is therefore stored in Turnkey and readable by every user of the organization. Do not sign a message you would not show them. A transaction's activity holds the signed transaction, which anyone who reads it can broadcast, so reject a pending transaction activity the plugin gave up on. A key with transactionSigning: "digest" leaves only the digest in Turnkey, which nobody can broadcast.

  • The plugin uses only the signature of Turnkey's signed transaction. It decodes the transaction Turnkey returns and refuses it unless its type and every field equal the transaction it sent (turnkey.sign.transaction-mismatch). The core then checks the signature against its own transaction's hash and broadcasts its own bytes.

The plugin's own checks apply to Turnkey as to every provider: each signature is normalized to low-S and must recover to the address pin before it is used, and the API private key never appears in output, logs or errors.

Safe proposals

kms safe propose, from @hardhat-kms/safe, signs a Safe transaction with an owner of the Safe and posts it to the Safe Transaction Service (Propose Safe transactions from Hardhat). The owner is the network's KMS key by default, or with --from a key in the network's accounts or a Ledger. It signs EIP-712 typed data through the connection. For a KMS key, the typed-data chain check and the signature check apply as for any typed data; for every proposer, the task's own checks below apply.

A local key is on disk: encrypted by hardhat-keystore, or in plain text in an environment variable or a .env file, and in Hardhat's memory while the task runs. Anyone who can read it can sign as that owner, propose, and with a threshold of 1 execute; nothing records its signatures. A KMS key never leaves the KMS, the cloud's IAM decides who may sign, and its audit log records each signature, so it is the recommended proposer for CI and long-lived owners. A Ledger keeps the key on the device and asks a person to approve each signature. A KMS key or a private key in .env compares them.

What the task protects against:

  • A signature by the node. On an http network whose accounts is "remote", eth_accounts lists the node's own accounts, and Hardhat would forward a signing request for one of them to the node. The task refuses a --from address there, and on any network config it does not recognise, unless it is a KMS or Ledger account of the network, and refuses any address the connection does not list, before anything signs.
  • A signature for another Safe or chain. It reads the Safe on the network's node and refuses a Safe without code, a version other than 1.3.0, 1.4.1 or 1.5.0, and a proposer that is not an owner. Safes before 1.3.0 sign without the chain id, so they are refused. The Safe's own getTransactionHash must equal the hash the plugin computed.
  • A transaction that cannot run, or pays someone. It refuses a nonce below the Safe's, and always sets the gas refund fields to zero.
  • A service that pushes the nonce far ahead. The plugin trusts the Transaction Service only to raise the default nonce above the Safe's, and by at most 50; beyond that it refuses and asks for --nonce.
  • A delegatecall by mistake. A delegatecall runs the target's code with the Safe's storage, so it can change the owners and move the funds. The task proposes one only with --delegatecall.
  • A proposal no Safe would accept. After signing, the signature must recover to the proposer's address and pass the Safe's checkNSignatures before anything is posted, whichever plugin signed.
  • A signature that executes on its own. For a Safe whose threshold is 1, the proposer's signature is enough to execute, and the service makes it public. The task asks a person at a terminal first, as kms sign-auth does, and refuses without one unless --yes is passed.
  • A leaked API key. kmsSafe.apiKey is a configuration variable only. The key goes only to the configured service as a bearer token, never into an error or a log, and the client never follows a redirect, so neither the key nor a signed proposal reaches another host.

What it does not protect against:

  • What the call does. The task checks that the Safe can run the call, not that you should. The other owners review it in the Safe app.
  • A node or a service that lies. The checks read the node you configured. A node that lies about the Safe can hide a change of owners until the service or the Safe refuses the signature. A service that hides a queued transaction can make the proposer sign another at the same nonce; the other owners see both in the Safe app, and only one can run. The service sees every proposal; anyone with its URL can read queued transactions and their signatures.
  • A later change of threshold. Owners, threshold and nonce are read at latest before signing. If the owners later lower the threshold, a proposal the owner signed can become executable with fewer signatures. That holds for any signed SafeTx.
  • A leaked local key. The task's checks decide what the plugin signs, not what someone else can sign with a copy of the key.
  • proposeSafeTransaction on a remote node. The library function sends the request for sender as it is and cannot see the network config: on a network with accounts: "remote", a sender that is not a KMS, Ledger or local account is signed by the node, unless the script calls assertProposerSignsInProcess first.
  • A Ledger's hash screen. hardhat-ledger falls back to signing the domain hash and message hash after any failure of the typed-data screen, a rejection included. Compare both with the task's summary, or reject them.
  • Code in the same process. Like the other tasks, kms safe propose and proposeSafeTransaction can be run from code, with yes or without approve, as What the plugin does not protect against says.

Audit logs

Each cloud provider records sign requests in its own audit log, whoever makes them. kms history reads that log for one key. It shows only what the log holds: the plugin keeps no record of its own signatures, and it fills in nothing. So the history can show who signed with a key, when, from where and with which tool, including signatures made outside the plugin. It cannot show what was signed: no provider logs the message, the typed data, the transaction or the signature. Google Cloud logs the digest; AWS and Azure do not. Find who signed with a key shows how to read the log after an incident and match its events to transactions.

What each provider records for a sign request, from the providers' documentation on 2026-10-02. Each reader's live test checked its column against real log entries the same day. On AWS, requestID is the $metadata.requestId the SDK returns. On Azure, CorrelationId is the x-ms-request-id that Key Vault returns, and the client's x-ms-client-request-id is not logged.

Field AWS KMS (CloudTrail Sign) Google Cloud KMS (AsymmetricSign) Azure Key Vault (KeySign in AZKVAuditLogs)
Time eventTime timestamp TimeGenerated
Principal userIdentity authenticationInfo.principalEmail the token claims in Identity: upn or unique_name for a user, appid for an application, and oid
Key and version key ARN in resources; no version resourceName, the full key version name Id, the versioned key URL; RequestUri too, with a port
Source IP sourceIPAddress requestMetadata.callerIp, which may be private CallerIpAddress
User agent userAgent requestMetadata.callerSuppliedUserAgent ClientInfo
Request id requestID, set by the service not logged; see below CorrelationId, set by the service
Digest not logged request.digest.sha256, 64 lowercase hex; the reader adds 0x not logged
Outcome errorCode, errorMessage status HttpStatusCode; ResultType is Success for a refused request too
Setup none, on by default Data Access logs for Cloud KMS, off by default a diagnostic setting to a Log Analytics workspace, resource-specific
Delay about 5 minutes, not guaranteed not documented up to 10 minutes
Retention 90 days 30 days in the _Default bucket set on the workspace; 30 days by default
Read permission cloudtrail:LookupEvents roles/logging.privateLogViewer Log Analytics Data Reader on the workspace

Google Cloud logs no request id: the only id of an entry is its insertId. Its reader lists requestId in notLogged and puts the insertId in extra.insertId.

What this means for you:

  • An empty history proves little. On Google Cloud and Azure, logging can be off, a caller can be exempted, logs can be routed elsewhere, and a read without access to the table may return no rows. On AWS, CloudTrail event history is kept per account and Region, and the read uses your credentials: a key used from another account, or read from another account or Region, can show nothing. It records every successful sign request, but a cross-account request refused for access only in the caller's account. kms history says so instead of reporting "no signatures", unless the reader confirms that it sees every sign request on the key.
  • The user agent is a claim. The plugin's requests can carry a hardhat-kms/<version> user agent, but any client can send the same string.
  • Retries show up. One signature can appear as several log entries for the same digest; see How many sign requests one call can send.
  • The output is sensitive. It holds principals, IP addresses and user agents. Key ids, provider id fields and error messages are masked unless you pass --show-ids. An id shorter than 6 characters is not masked, and one of 6 or 7 characters, such as a short Google Cloud project id, is masked only where it stands as a whole word. Principals are not masked, so an AWS principal ARN shows its account id. The one exception: a value the plugin hides everywhere, such as a Google Cloud project id from a configuration variable, is hidden inside a principal's email too. That is accepted, since the variable exists to keep the project out of the output.
  • Reading signs nothing. The task holds no key material and makes no signing call. On AWS, finding the key ARN of an alias or a bare key id needs one GetPublicKey call, which CloudTrail logs.

Read next