key.go 1.19 KB
Newer Older
1 2 3 4
package iface

import (
	"context"
Łukasz Magiera's avatar
Łukasz Magiera committed
5
	path "github.com/ipfs/interface-go-ipfs-core/path"
6

Łukasz Magiera's avatar
Łukasz Magiera committed
7
	"github.com/ipfs/interface-go-ipfs-core/options"
8

Raúl Kripalani's avatar
Raúl Kripalani committed
9
	"github.com/libp2p/go-libp2p-core/peer"
10 11 12 13 14 15
)

// Key specifies the interface to Keys in KeyAPI Keystore
type Key interface {
	// Key returns key name
	Name() string
16

17
	// Path returns key path
Łukasz Magiera's avatar
Łukasz Magiera committed
18
	Path() path.Path
19

20 21
	// ID returns key PeerID
	ID() peer.ID
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
}

// KeyAPI specifies the interface to Keystore
type KeyAPI interface {
	// Generate generates new key, stores it in the keystore under the specified
	// name and returns a base58 encoded multihash of it's public key
	Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)

	// Rename renames oldName key to newName. Returns the key and whether another
	// key was overwritten, or an error
	Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (Key, bool, error)

	// List lists keys stored in keystore
	List(ctx context.Context) ([]Key, error)

37 38 39
	// Self returns the 'main' node key
	Self(ctx context.Context) (Key, error)

40
	// Remove removes keys from keystore. Returns ipns path of the removed key
41
	Remove(ctx context.Context, name string) (Key, error)
42
}