diff --git a/bip-0322.mediawiki b/bip-0322.mediawiki
index cf9c5539..20b68c85 100644
--- a/bip-0322.mediawiki
+++ b/bip-0322.mediawiki
@@ -13,19 +13,33 @@
== Abstract ==
-A standard for interoperable signed messages based on the Bitcoin Script format, either for proving fund availability, or committing to a message as the intended recipient of funds sent to the invoice address.
+A standard for interoperable signed messages based on the Bitcoin Script format, either for proving
+fund availability, or committing to a message as the intended recipient of funds sent to the invoice
+address.
== Motivation ==
-The current message signing standard only works for P2PKH (1...) invoice addresses. We propose to extend and generalize the standard by using a Bitcoin Script based approach. This ensures that any coins, no matter what script they are controlled by, can in-principle be signed for. For easy interoperability with existing signing hardware, we also define a signature message format which resembles a Bitcoin transaction (except that it contains an invalid input, so it cannot be spent on any real network).
+The current message signing standard only works for P2PKH (1...) invoice addresses. We propose to
+extend and generalize the standard by using a Bitcoin Script based approach. This ensures that any
+coins, no matter what script they are controlled by, can in-principle be signed for. For easy
+interoperability with existing signing hardware, we also define a signature message format which
+resembles a Bitcoin transaction (except that it contains an invalid input, so it cannot be spent on
+any real network).
-Additionally, the current message signature format uses ECDSA signatures which do not commit to the public key, meaning that they do not actually prove knowledge of any secret keys. (Indeed, valid signatures can be tweaked by 3rd parties to become valid signatures on certain related keys.)
+Additionally, the current message signature format uses ECDSA signatures which do not commit to the
+public key, meaning that they do not actually prove knowledge of any secret keys. (Indeed, valid
+signatures can be tweaked by 3rd parties to become valid signatures on certain related keys.)
-Ultimately no message signing protocol can actually prove control of funds, both because a signature is obsolete as soon as it is created, and because the possessor of a secret key may be willing to sign messages on others' behalf even if it would not sign actual transactions. No signmessage protocol can fix these limitations.
+Ultimately no message signing protocol can actually prove control of funds, both because a signature
+is obsolete as soon as it is created, and because the possessor of a secret key may be willing to
+sign messages on others' behalf even if it would not sign actual transactions. No signmessage
+protocol can fix these limitations.
== Types of Signatures ==
-This BIP specifies three formats for signing messages: ''legacy'', ''simple'' and ''full''. Additionally, a variant of the ''full'' format can be used to demonstrate control over a set of UTXOs.
+This BIP specifies three formats for signing messages: ''legacy'', ''simple'' and ''full''.
+Additionally, a variant of the ''full'' format can be used to demonstrate control over a set of
+UTXOs.
{| class="wikitable"
|- style="font-weight:bold;"
@@ -50,7 +64,8 @@ This BIP specifies three formats for signing messages: ''legacy'', ''simple'' an
| full to_sign transaction, consensus and base64-encoded
|}
-1: Possible on a technical level but should NOT be used anymore in the context of this BIP.
+1: Possible on a technical level but should NOT be used anymore in the context of this
+BIP.
2: Excluding time lock scripts.
=== Legacy ===
@@ -61,17 +76,29 @@ The legacy format MAY be used, but must be restricted to the legacy P2PKH invoic
=== Simple ===
-A ''simple'' signature consists of a witness stack, consensus encoded as a vector of vectors of bytes, and base64-encoded. Validators should construct to_spend and to_sign as defined below, with default values for all fields except that
+A ''simple'' signature consists of a witness stack, consensus encoded as a vector of vectors of
+bytes, and base64-encoded. Validators should construct to_spend and
+to_sign as defined below, with default values for all fields except that
-* message_hash is a BIP340-tagged hash of the message, as specified below
-* message_challenge in to_spend is set to the scriptPubKey being signed with
-* message_signature in to_sign is set to the provided simple signature.
+
message_hash is a BIP340-tagged hash of the message, as specified below
+message_challenge in to_spend is set to the scriptPubKey being signed
+ with
+message_signature in to_sign is set to the provided simple signature.
+to_spend and to_sign.
@@ -87,7 +114,10 @@ The to_spend transaction is:
vout[0].nValue = 0
vout[0].scriptPubKey = message_challenge
-where message_hash is a BIP340-tagged hash of the message, i.e. sha256_tag(m), where tag = BIP0322-signed-message and m is the message as is without length prefix or null terminator, and message_challenge is the to be proven (public) key script.
+where message_hash is a BIP340-tagged hash of the message, i.e. sha256_tag(m), where
+tag = BIP0322-signed-message and m is the message as is without length
+prefix or null terminator, and message_challenge is the to be proven (public) key
+script.
The to_sign transaction is:
@@ -101,26 +131,48 @@ The to_sign transaction is:
vout[0].nValue = 0
vout[0].scriptPubKey = OP_RETURN
-A full signature consists of the base64-encoding of the to_sign transaction in standard network serialisation once it has been signed.
+A full signature consists of the base64-encoding of the to_sign transaction in standard
+network serialisation once it has been signed.
=== Full (Proof of Funds) ===
-A signer may construct a proof of funds, demonstrating control of a set of UTXOs, by constructing a full signature as above, with the following modifications.
+A signer may construct a proof of funds, demonstrating control of a set of UTXOs, by constructing a
+full signature as above, with the following modifications.
-* All outputs that the signer wishes to demonstrate control of are included as additional inputs of to_sign, and their witness and scriptSig data should be set as though these outputs were actually being spent.
+to_sign, and their witness and scriptSig data should be set as though these
+ outputs were actually being spent.
+to_spend and to_sign transactions must be valid transactions which pass all consensus checks, except of course that the output with prevout 000...000:FFFFFFFF does not exist.
+For all signature types, except legacy, the to_spend and to_sign
+transactions must be valid transactions which pass all consensus checks, except of course that the
+output with prevout 000...000:FFFFFFFF does not exist.
=== Verification ===
-A validator is given as input an address ''A'' (which may be omitted in a proof-of-funds), signature ''s'' and message ''m'', and outputs one of three states
-* ''valid at time T and age S'' indicates that the signature has set timelocks but is otherwise valid
-* ''inconclusive'' means the validator was unable to check the scripts
-* ''invalid'' means that some check failed
+A validator is given as input an address ''A'' (which may be omitted in a proof-of-funds), signature
+''s'' and message ''m'', and outputs one of three states
+
+to_spend and to_sign as specified above, using the scriptPubKey of ''A'' for message_challenge and tagged hash of ''m'' as message_hash.
-# Optionally, they may set nLockTime of to_sign or nSequence of its first input.
-# Optionally, they may add any additional inputs to to_sign that they wish to prove control of.
-# They satisfy to_sign as they would any other transaction.
+to_spend and to_sign as specified above, using the
+ scriptPubKey of ''A'' for message_challenge and tagged hash of ''m'' as
+ message_hash.
+to_sign or nSequence of its first input.
+to_sign that they wish to prove
+ control of.
+to_sign as they would any other transaction.
+to_sign, left nSequence and nLockTime at 0, and ''A'' is a Segwit address (either pure or P2SH-wrapped), then they may base64-encode message_signature
-* Otherwise they must base64-encode to_sign.
+to_sign, left nSequence and nLockTime at 0, and ''A'' is a
+ Segwit address (either pure or P2SH-wrapped), then they may base64-encode
+ message_signature
+to_sign.
+basic-test-vectors.json]].
+Basic test vectors for message hashing, transaction hashes and "simple" variant test cases can be
+found in [[bip-0322/basic-test-vectors.json|basic-test-vectors.json]].
-Generated test vectors for more "simple" and "full" variant test cases can be found in [[bip-0322/generated-test-vectors.json|generated-test-vectors.json]].
+Generated test vectors for more "simple" and "full" variant test cases can be found in
+[[bip-0322/generated-test-vectors.json|generated-test-vectors.json]].
-They were generated using [https://github.com/guggero/btcd/blob/f0d8719873ac70412dd813ef6e81358864c4eaa3/btcutil/bip322/bip322_test.go#L910 this code].
+They were generated using
+[https://github.com/guggero/btcd/blob/f0d87198/btcutil/bip322/bip322_test.go#L910 this code].