contract DocSigner {

// -------------------------------------------------------------
// STATE DECLARATION
// -------------------------------------------------------------

    address public owner;// Redenbach-Lee address
    uint constant maxSigs = 10; // maximum number of counterparties
    uint numSigs = 0; // number of signatures for the next signing
    string public docHash; // current document hash
    address[10] signatories; // signatory addresses
    mapping(address => string) public messages;

// -------------------------------------------------------------
// CONSTRUCTOR
// -------------------------------------------------------------

    function DocSigner()
        public
    {
        owner = msg.sender;
    }

// -------------------------------------------------------------
// EVENTS
// -------------------------------------------------------------

    event Signature(address signer, string docHash, string message);

// -------------------------------------------------------------
// FUNCTIONS
// -------------------------------------------------------------

    /*
      This is the initialisation function for a new legal contract.
      The contract owner sets the new agreement hash and the
      number of signatories.
    */

    function setup( string   newDocHash,
                    address[] newSigs )
        external
        onlyOwner
    {
        require( newSigs.length <= maxSigs ); // bound array

        docHash = newDocHash;
        numSigs = newSigs.length;

        for( uint i = 0; i < numSigs; i++ ){
            signatories[i] = newSigs[i];
        }
    }

    /*
      This is the function used by signatories to confirm
      their agreement over the document hash.
    */

    function sign( string signingHash,
                   string message )
        external
        onlySigner
    {
        require(keccak256(signingHash) == keccak256(docHash));

        // save the message to state so that it can be easily queried
        messages[msg.sender] = message;

        Signature(msg.sender, docHash, message);
    }

    /*
      Check if the address is within the approved signatories list.
    */

    function checkSig(address addr)
        internal
        view
        returns (bool)
    {
        for( uint i = 0; i < numSigs; i++ ){
            if( signatories[i] == addr )
                return true;
        }

        return false;
    }

// -------------------------------------------------------------
// MODIFIERS
// -------------------------------------------------------------

    modifier onlyOwner
    {
        require(msg.sender == owner);
        _;
    }

    modifier onlySigner
    {
        require(checkSig(msg.sender));
        _;
    }
}
function sign( string signingHash,
               string message )
    external
    onlySigner
{
    require(keccak256(signingHash) == keccak256(docHash));

    // save the message to state so that it can be easily queried
    messages[msg.sender] = message;

    Signature(msg.sender, docHash, message);
}

/*
 This is the function used by signatories to confirm
 their agreement over the document hash.
 */