How to sign contractTransactionHash in web3js?

Hi Gnosis forum

I’m referring to:

Sign
pip install eth_account
python3
from eth_account import Account
from hexbytes import HexBytes
contract_transaction_hash = HexBytes(‘0x1ed9d878f89585977e98425d5cedf51027c041e414bb471d64519f8f510bb555’)
account = Account.from_key(‘0x66e91912f68828c17ad3fee506b7580c4cd19c7946d450b4b0823ac73badc878’)
signature = account.signHash(contract_transaction_hash)
print(signature.signature.hex())

Signature is 0xc0df6a1b659d56d3d23f66cbd1c483467ea68a428fea7bbbe0a527d43d8681f616af33344035f36c08218718480374dada0fe6cdb266d0182a4225d0e9c227181b.

How to sign contractTransactionHash in web3js and get the same signature?

I use: https://web3js.readthedocs.io/en/v1.3.4/

I tried many ways, I can’t get it.

Here is how I tried it:

npx truffle console --network rinkeby

truffle(rinkeby)> const msgByteArray = web3.utils.hexToBytes(‘0x1ed9d878f89585977e98425d5cedf51027c041e414bb471d64519f8f510bb555’);

truffle(rinkeby)> const msgBuf = new Buffer.from(msgByteArray);

truffle(rinkeby)> const prefixBuf = new Buffer("\x19Ethereum Signed Message:\n");

truffle(rinkeby)> var dataConcatBuf = new Buffer.concat([prefixBuf, new Buffer(String(msgBuf.length)), msgBuf]);

truffle(rinkeby)> var dataConcatHex = ‘0x’ + dataConcatBuf.toString(‘hex’);

truffle(rinkeby)> var dataConcatHash = web3.utils.sha3(dataConcatHex);

truffle(rinkeby)> web3.eth.accounts.sign(dataConcatHash, ‘0x66e91912f68828c17ad3fee506b7580c4cd19c7946d450b4b0823ac73badc878’);

Here is what I got:
{
message:
‘0x92c6d7068059541058e483cc8e1c77b022b12c0e145c1bde2a33fa867db9775c’,
messageHash:
‘0x6474e33af69388e3b6e830e45b1bfa7470f0e2bff82cdd191c1f4d1e023c17e7’,
v: ‘0x1c’,
r:
‘0xf2c25d778985db633068fb3301d36d23308ab627a3af8706c4ab768068008699’,
s:
‘0x5f209319d27f34fa0f2f0708dcb7ee4f08a4aa6610a4c70e436442495a7687d5’,
signature:
‘0xf2c25d778985db633068fb3301d36d23308ab627a3af8706c4ab7680680086995f209319d27f34fa0f2f0708dcb7ee4f08a4aa6610a4c70e436442495a7687d51c’
}

Thank you

Best Regards
Configentia