drand/tlock

Add API around the actual Timelock and TimeUnlock features

AnomalRoil opened this issue · 1 comments

Let us have a set of API that's independent of the Network and does the actual Timelock

Something roughly like this:

func TimeLock(plaintext []byte, roundnumber uint64, drandPublicKey kyber.Point) (cipher ibe.Ciphertext, error) {

  id, err := calculateEncryptionID(t.round)
	  if err != nil {
...
	  }
  
	  cipherText, err := ibe.Encrypt(bls.NewBLS12381Suite(), drandPublicKey, id, plaintext)
	  if err != nil {
....
	  }
}

func TimeUnlock(ciphertext ibe.Ciphertext, beacon chain.Beacon) (plaintext []byte, error) {
    var signature bls.KyberG2
	if err := signature.UnmarshalBinary(beacon.Signature()); err != nil {
...
	}

	plaintext, err = ibe.Decrypt(bls.NewBLS12381Suite(), &signature, &ciphertext)
if ...
}

feel free to wrap the type ibe.Ciphertext into a custom type too.

We pushed code for these API's now. Funny thing is we identified these API before reading this issue, which I think is a good thing. Please review the parameters we came up with (which are very close).