Skip to content

Commit a56eade

Browse files
committed
coreapi: Documentation for Name/Key
License: MIT Signed-off-by: Łukasz Magiera <[email protected]>
1 parent 4c8747f commit a56eade

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

core/coreapi/interface/interface.go

+47
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,73 @@ type UnixfsAPI interface {
6565
Ls(context.Context, Path) ([]*Link, error)
6666
}
6767

68+
// NameAPI specifies the interface to IPNS.
69+
//
70+
// IPNS is a PKI namespace, where names are the hashes of public keys, and the
71+
// private key enables publishing new (signed) values. In both publish and
72+
// resolve, the default name used is the node's own PeerID, which is the hash of
73+
// its public key.
74+
//
75+
// You can use .Key API to list and generate more names and their respective keys.
6876
type NameAPI interface {
77+
// Publish announces new IPNS name
6978
Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (*IpnsEntry, error)
79+
80+
// WithValidTime is an option for Publish which specifies for how long the
81+
// entry will remain valid. Default value is 24h
7082
WithValidTime(validTime time.Duration) options.NamePublishOption
83+
84+
// WithKey is an option for Publish which specifies the key to use for
85+
// publishing. Default value is "self" which is the node's own PeerID.
86+
//
87+
// You can use .Key API to list and generate more names and their respective keys.
7188
WithKey(key string) options.NamePublishOption
7289

90+
// Resolve attempts to resolve the newest version of the specified name
7391
Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
92+
93+
// WithRecursive is an option for Resolve which specifies whether to perform a
94+
// recursive lookup. Default value is false
7495
WithRecursive(recursive bool) options.NameResolveOption
96+
97+
// WithLocal is an option for Resolve which specifies if the lookup should be
98+
// offline. Default value is false
7599
WithLocal(local bool) options.NameResolveOption
100+
101+
// WithNoCache is an option for Resolve which specifies when set to true
102+
// disables the use of local name cache. Default value is false
76103
WithNoCache(nocache bool) options.NameResolveOption
77104
}
78105

106+
// KeyAPI specifies the interface to Keystore
79107
type KeyAPI interface {
108+
// Generate generates new key, stores it in the keystore under the specified
109+
// name and returns a base58 encoded multihash of it's public key
80110
Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (string, error)
111+
112+
// WithAlgorithm is an option for Generate which specifies which algorithm
113+
// should be used for the key. Default is "rsa"
114+
//
115+
// Supported algorithms:
116+
// * rsa
117+
// * ed25519
81118
WithAlgorithm(algorithm string) options.KeyGenerateOption
119+
120+
// WithSize is an option for Generate which specifies the size of the key to
121+
// generated. Default is 0
82122
WithSize(size int) options.KeyGenerateOption
83123

124+
// Rename renames oldName key to newName.
84125
Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (string, bool, error)
126+
127+
// WithForce is an option for Rename which specifies whether to allow to
128+
// replace existing keys.
85129
WithForce(force bool) options.KeyRenameOption
86130

131+
// List lists keys stored in keystore
87132
List(ctx context.Context) (map[string]string, error) //TODO: better key type?
133+
134+
// Remove removes keys from keystore
88135
Remove(ctx context.Context, name string) (string, error)
89136
}
90137

core/coreapi/key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
3030
switch options.Algorithm {
3131
case "rsa":
3232
if options.Size == 0 {
33-
return "", fmt.Errorf("please specify a key size with --size")
33+
return "", fmt.Errorf("please specify a key size with WithSize option")
3434
}
3535

3636
priv, pub, err := crypto.GenerateKeyPairWithReader(crypto.RSA, options.Size, rand.Reader)

0 commit comments

Comments
 (0)