mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
// Copyright 2014 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// Modified by Prysmatic Labs 2018
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package keystore
|
|
|
|
import (
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
|
|
prysmTime "github.com/prysmaticlabs/prysm/v3/time"
|
|
)
|
|
|
|
func aesCTRXOR(key, inText, iv []byte) ([]byte, error) {
|
|
// AES-128 is selected due to size of encryptKey.
|
|
aesBlock, err := aes.NewCipher(key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
stream := cipher.NewCTR(aesBlock, iv)
|
|
outText := make([]byte, len(inText))
|
|
stream.XORKeyStream(outText, inText)
|
|
return outText, err
|
|
}
|
|
|
|
func ensureInt(x interface{}) int {
|
|
res, ok := x.(int)
|
|
if !ok {
|
|
res = int(x.(float64))
|
|
}
|
|
return res
|
|
}
|
|
|
|
// keyFileName implements the naming convention for keyfiles:
|
|
// UTC--<created_at UTC ISO8601>-<first 8 character of address hex>
|
|
func keyFileName(pubkey bls.PublicKey) string {
|
|
ts := prysmTime.Now().UTC()
|
|
return fmt.Sprintf("UTC--%s--%s", toISO8601(ts), hex.EncodeToString(pubkey.Marshal())[:8])
|
|
}
|
|
|
|
func toISO8601(t time.Time) string {
|
|
var tz string
|
|
name, offset := t.Zone()
|
|
if name == "UTC" {
|
|
tz = "Z"
|
|
} else {
|
|
tz = fmt.Sprintf("%03d00", offset/3600)
|
|
}
|
|
return fmt.Sprintf("%04d-%02d-%02dT%02d-%02d-%02d.%09d%s", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), tz)
|
|
}
|