forked from External/ergo
factor out confirmation codes into utils, change their format
This commit is contained in:
parent
490b3722bd
commit
85a536977c
5 changed files with 63 additions and 15 deletions
22
irc/utils/confirmation.go
Normal file
22
irc/utils/confirmation.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) 2020 Shivaram Lingamneni <slingamn@cs.stanford.edu>
|
||||
// released under the MIT license
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Deterministically generates a confirmation code for some destructive activity;
|
||||
// `name` is typically the name of the identity being destroyed (a channel being
|
||||
// unregistered, or the server being crashed) and `createdAt` means a different
|
||||
// value is required each time.
|
||||
func ConfirmationCode(name string, createdAt time.Time) (code string) {
|
||||
buf := make([]byte, len(name)+8)
|
||||
binary.BigEndian.PutUint64(buf, uint64(createdAt.UnixNano()))
|
||||
copy(buf[8:], name[:])
|
||||
out := sha256.Sum256(buf)
|
||||
return B32Encoder.EncodeToString(out[:3])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue