github.com/ethersphere/bee/v2@v2.2.0/pkg/keystore/keystore.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package keystore
     6  
     7  import (
     8  	"crypto/ecdsa"
     9  	"errors"
    10  )
    11  
    12  // ErrInvalidPassword is returned when the password for decrypting content where
    13  // private key is stored is not valid.
    14  var ErrInvalidPassword = errors.New("invalid password")
    15  
    16  // EDG represents and encoder/decoder/generator for ECDSA private keys
    17  type EDG interface {
    18  	Generate() (*ecdsa.PrivateKey, error)
    19  	Encode(k *ecdsa.PrivateKey) ([]byte, error)
    20  	Decode(data []byte) (*ecdsa.PrivateKey, error)
    21  }
    22  
    23  // Service for managing keystore private keys.
    24  type Service interface {
    25  	// Key returns the private key for a specified name that was encrypted with
    26  	// the provided password. If the private key does not exists it creates
    27  	// a new one with a name and the password, and returns with created set
    28  	// to true.
    29  	Key(name, password string, edg EDG) (pk *ecdsa.PrivateKey, created bool, err error)
    30  	// Exists returns true if the key with specified name exists.
    31  	Exists(name string) (bool, error)
    32  	// SetKey generates and persists a new private key
    33  	SetKey(name, password string, edg EDG) (*ecdsa.PrivateKey, error)
    34  }