The Basics of ERC-1271

While this works for EOAs, which have private keys, it does not work for Smart Contracts, and specifically Smart Contract Wallets. This is because Smart Contracts have no "private keys", to use for elliptic curve cryptography. Meaning, that Smart Contracts really be used for ECDSA signing. In order to work around this, a different signature is needed that does not depend on elliptic curve cryptography.
The solution was to standardise a new form of on-chain signature verification for Smart Contracts: ERC-1271. This is a simple standard that requires Smart Contracts that want to perform signature verification to implement a isValidSignature method:
The interface is very simple, but also incredibly flexible. The verifying Smart Contract would get passed in the 32-byte hash that it wants to verify along with an implementation dependant arbitrary length byte array. This arbitrary length byte array allows all kinds of data to be encoded and passed in, making signature verification extremely powerful. Also, since this is just a Smart Contract CALL, the logic that verifies the signature can be arbitrary and make use of any on-chain state that it wants.
With respect to CoW Protocol orders, the flow now becomes:
  1. 1.
    Like before, prepare your order, i.e. the structured order data
  2. 2.
    Like before, hash this structured data into a 32-byte digest
  3. 3.
    Unlike before, call the isValidSignature on the Smart Contract signer instead of performing the usual ECDSA signature recovery and validation