my Question in short is:
-> is it possible to digitally sign some data by a smart contract (e.g. with a secret key of the contract) and thus confirm that it was exactly this smart contract, who signed the data? -> I already kind of know, that it probably won't work that way, because a contract's data and code is entirely public and thus it can't keep a secret. So are there any clever on-chain workarounds, or would I have to use off-chain steps with this one..?
Now with a bit of background:
I'm trying to create a dapp, in which a creator can sign a document and have it timestamped on the Blockchain, so that anyone can verify wether the document existested at a certain point in time.
My concept so far was:
Document gets hashed and then signed by the creator's private key (client side, off chain) -> thus creating a digital signature of the document
The signature is then sent to a smart contract, which appends a timestamp to the signature, hashes both together and then the contract signes the hash)(the timestamp represents the current block's time)
The Contract stores a mapping where each row (one row for each document or its version) is accessed with the hash of the document, pointing to a struct with: the timestamp, the signature of the creator and the timestamp signed by the contract itself.
Now anyone with access to the document, the creators public key and the contracts public key could verify (with the signed hashes in the mapping), that
a) the document was signed by the creator
b) the document was timestamped and signed by the smart contract
-> My original goal was to avoid having trusted third parties included into the process at all (neither for timestamping, nor signing)
So the Problems seem to be:
-> since a smart contract cannot store a secret on chain(as far as I know), I cannot securely store a private key in the contract, with which it could sign data
-> also, if I stored a secret key somewhere off chain, how could a smart contract be authorized to access it? (since it has no private key to be identified with)
It would really be awesome if you could help me out! Thank you!