docs for coreapi key method impls
License: MIT Signed-off-by: ForrestWeston <forrest@protocol.ai>
ForrestWeston committed
Jan 22, 2018 at 14:45 UTC
252ddc829529a103341d10d95ca34db8b0fb5b18
1 file changed
+8
core/coreapi/key.go
+8
@@ -24,14 +24,18 @@ type key struct {
24
peerId string
25
}
26
27
+// Name returns the key name
28
func (k *key) Name() string {
29
return k.name
30
}
31
32
+// Path returns the path of the key.
33
func (k *key) Path() coreiface.Path {
34
return &path{path: ipfspath.FromString(ipfspath.Join([]string{"/ipns", k.peerId}))}
35
}
36
37
+// Generate generates new key, stores it in the keystore under the specified
38
+// name and returns a base58 encoded multihash of its public key.
39
func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.KeyGenerateOption) (coreiface.Key, error) {
40
options, err := caopts.KeyGenerateOptions(opts...)
41
if err != nil {
@@ -88,6 +92,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
92
return &key{name, pid.Pretty()}, nil
93
}
94
95
+// List returns a list keys stored in keystore.
96
func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) {
97
keys, err := api.node.Repo.Keystore().List()
98
if err != nil {
@@ -117,6 +122,8 @@ func (api *KeyAPI) List(ctx context.Context) ([]coreiface.Key, error) {
122
return out, nil
123
}
124
125
+// Rename renames `oldName` to `newName`. Returns the key and whether another
126
+// key was overwritten, or an error.
127
func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, opts ...caopts.KeyRenameOption) (coreiface.Key, bool, error) {
128
options, err := caopts.KeyRenameOptions(opts...)
129
if err != nil {
@@ -169,6 +176,7 @@ func (api *KeyAPI) Rename(ctx context.Context, oldName string, newName string, o
176
return &key{newName, pid.Pretty()}, overwrite, ks.Delete(oldName)
177
}
178
179
+// Remove removes keys from keystore. Returns ipns path of the removed key.
180
func (api *KeyAPI) Remove(ctx context.Context, name string) (coreiface.Path, error) {
181
ks := api.node.Repo.Keystore()
182