Documentation
¶
Index ¶
- Constants
- Variables
- func EncryptKey(OptionalInfo string, key *Key, auth string, scryptN, scryptP int) ([]byte, error)
- func Fatalf(format string, args ...interface{})
- func FromECDSACRYPTO(priv *ecdsa.PrivateKey) []byte
- func FromECDSACRYPTOPub(pub *ecdsa.PublicKey) []byte
- func FromPriECDSACRYPTOPub(priv *ecdsa.PrivateKey) []byte
- func GenerateKey_ZL() (pubkey, seckey []byte)
- func GetEntropyCSPRNG(n int) []byte
- func Keccak256(data ...[]byte) []byte
- func NewAuthNeededError(needed string) error
- func NewKeccak256() hash.Hash
- func PaddedBigBytes(bigint *big.Int, n int) []byte
- func ReadBits(bigint *big.Int, buf []byte)
- func S256() elliptic.Curve
- func ToECDSACRYPTO(d []byte) (*ecdsa.PrivateKey, error)
- func ToECDSACRYPTOPub(pub []byte) *ecdsa.PublicKey
- func ToECDSACRYPTOUnsafe(d []byte) *ecdsa.PrivateKey
- func WriteKeyFile(file string, content []byte) error
- type AuthNeededError
- type Key
- type UUID
Constants ¶
const ( HashLength = 32 UUIDLength = 20 )
const ( // StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptN = 1 << 18 // StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptP = 1 // LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptN = 1 << 12 // LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptP = 6 )
Variables ¶
var ( Big1 = big.NewInt(1) Big2 = big.NewInt(2) Big3 = big.NewInt(3) Big0 = big.NewInt(0) Big32 = big.NewInt(32) Big256 = big.NewInt(256) Big257 = big.NewInt(257) )
var ( ErrLocked = NewAuthNeededError("password or unlock") ErrNoMatch = errors.New("no key for given address or file") ErrDecrypt = errors.New("could not decrypt key with given passphrase") )
var Pubkeytmp ecdsa.PublicKey
var Reader io.Reader = &randEntropy{}
Functions ¶
func EncryptKey ¶
EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.
func FromECDSACRYPTO ¶
func FromECDSACRYPTO(priv *ecdsa.PrivateKey) []byte
FromECDSACRYPTO exports a private key into a binary dump.
func FromECDSACRYPTOPub ¶
func FromPriECDSACRYPTOPub ¶
func FromPriECDSACRYPTOPub(priv *ecdsa.PrivateKey) []byte
FromECDSACRYPTOPub exports a private key into a binary dump.
func GenerateKey_ZL ¶
func GenerateKey_ZL() (pubkey, seckey []byte)
func GetEntropyCSPRNG ¶
func NewAuthNeededError ¶
NewAuthNeededError creates a new authentication error with the extra details about the needed fields set.
func ToECDSACRYPTO ¶
func ToECDSACRYPTO(d []byte) (*ecdsa.PrivateKey, error)
ToECDSACRYPTO creates a private key with the given D value.
func ToECDSACRYPTOPub ¶
func ToECDSACRYPTOUnsafe ¶
func ToECDSACRYPTOUnsafe(d []byte) *ecdsa.PrivateKey
ToECDSACRYPTOUnsafe blindly converts a binary blob to a private key. It should almost never be used unless you are sure the input is valid and want to avoid hitting errors due to bad origin encoding (0 prefixes cut off).
func WriteKeyFile ¶
Types ¶
type AuthNeededError ¶
type AuthNeededError struct {
Needed string // Extra authentication the user needs to provide
}
func (*AuthNeededError) Error ¶
func (err *AuthNeededError) Error() string
Error implements the standard error interface.
type Key ¶
type Key struct { Id uuid.UUID // Version 4 "random" for unique id not derived from key data // to simplify lookups we also store the address UUID UUID // we only store privkey as pubkey/address can be derived from it // privkey in this struct is always in plaintext PrivateKey *ecdsa.PrivateKey }
func DecryptKey ¶
DecryptKey decrypts a key from a json blob, returning the private key itself.
func KeyDecrypt ¶
Tests that a json key file can be decrypted and encrypted in multiple rounds.