This section details signing non-smart contract transactions. For auth related to smart contract transactions, see authorization.)
Thresholds
Each operation falls under a specific threshold category: low, medium, or high with a number level between 0-255 (to read more about this see our section on Operations and Transactions). This threshold determines what signature weight is needed to authorize an operation. To view each operation’s threshold, see our List of Operations section. Accounts can set their own signature weight, threshold values, and additional signing keys with the Set Options operation. By default, all operation threshold levels are set to 0, and the master key is set to weight 1. For most cases, it is recommended to set thresholds such thatlow <= medium <= high.
If the master key’s weight is set at 0, it cannot be used to sign transactions, even for operations with a threshold value of 0. Be very careful setting your master key weight to 0. Doing so may permanently lock you out of your account (although if there are other signers listed on the account, they can still continue to sign transactions.)
Authorization
To determine if a transaction has the necessary authorization to run, the weights of all the signatures in the transaction envelope are added up. If this sum is equal to or greater than the threshold for that operation type, then the operation is authorized. This scheme is very flexible. You can require many signers to authorize payments from a particular account. You can have an account that any number of people can authorize for. You can have a master key that grants access or revokes access from others. It supports any m of n setup.Multisig
In some cases, a transaction may need more than one signature:- If the transaction has operations with multiple source accounts, it requires the source account signature for each operation
- Additional signatures are required if the account associated with the transaction has multiple public keys
TX_BAD_AUTH_EXTRA. This design is because unnecessary signature verification has a large effect on performance before accepting transactions in consensus.
Alternate signature types
To enable some advanced smart contract features there are a couple of additional signature types. These signature types also have weights and can be added and removed similarly to normal signature types. But rather than check a cryptographic signature for authorization they have a different method of proving validity to the network.Pre-authorized Transaction
It is possible for an account to pre-authorize a particular transaction by adding the hash of the future transaction as a signer on the account. To do that, you need to prepare the transaction beforehand with the proper sequence number. Then you can obtain the hash of this transaction and add it as a signer to the account. Signers of this type are automatically removed from the account when a matching transaction is applied, regardless of whether the transaction succeeds or fails. In case a matching transaction is never submitted, the signer remains, and must be manually removed using the Set Options operation. This type of signer is especially useful in escrow accounts. You can pre-authorize two different transactions. Both could have the same sequence number but different destinations. This means that only one of them can be executed.Hash(x)
Hash(x) signing is a different concept from transaction hashes. Transaction hashes are unique identifiers generated by applying a cryptographic hash function to the data of a transaction in a blockchain. They serve as a digital fingerprint and allow users to verify and reference transactions on the network. Hash(x) is a signature type.
Examples
We’ll go through some examples of how powerful thresholding and weights are, below. If you want to learn more about using advanced signers likehash(x), check out this blog post for some fun examples.
- Example 1: Anchors
- Example 2: Joint accounts
- Example 3: Expense accounts
- Example 4: Company accounts
Example 1: Anchors
You run an anchor that would like to keep its issuing key offline. That way, it’s less likely a bad actor can get ahold of the anchor’s key and start issuing credit improperly. However, your anchor needs to authorize people holding credit by running theSet Trust Line Flags operation. Before you issue credit to an account, you need to verify that account is OK.
Multisig allows you to do all of this without exposing the master key of your anchor. You can add another signing key to your account with the operation Set Options. This additional key should have a weight below your anchor account’s medium threshold. Since Set Trust Line Flags is a low-threshold operation, this extra key authorizes users to hold your anchor’s credit. But, since Payment is a medium-threshold operation, this key does not allow anyone who compromises your anchor to issue credit.
Your account setup: