You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

confirmation.go 715B

12345678910111213141516171819202122
  1. // Copyright (c) 2020 Shivaram Lingamneni <slingamn@cs.stanford.edu>
  2. // released under the MIT license
  3. package utils
  4. import (
  5. "crypto/sha256"
  6. "encoding/binary"
  7. "time"
  8. )
  9. // Deterministically generates a confirmation code for some destructive activity;
  10. // `name` is typically the name of the identity being destroyed (a channel being
  11. // unregistered, or the server being crashed) and `createdAt` means a different
  12. // value is required each time.
  13. func ConfirmationCode(name string, createdAt time.Time) (code string) {
  14. buf := make([]byte, len(name)+8)
  15. binary.BigEndian.PutUint64(buf, uint64(createdAt.UnixNano()))
  16. copy(buf[8:], name[:])
  17. out := sha256.Sum256(buf)
  18. return B32Encoder.EncodeToString(out[:3])
  19. }