@cryptotaxi247 / kubo / commits / 587dc187c

coreapi: Documentation for Name/Key

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Dec 15, 2017 at 01:03 UTC 587dc187c69945d44e5781a4e5862cab52b2325e
3 files changed +50 -9
core/coreapi/coreapi.go
+2 -8
@@ -30,17 +30,11 @@ func (api *CoreAPI) Dag() coreiface.DagAPI {
30 }
31
32 func (api *CoreAPI) Name() coreiface.NameAPI {
33 - return &NameAPI{
34 - api,
35 - nil,
36 - }
33 + return &NameAPI{api, nil}
34 }
35
36 func (api *CoreAPI) Key() coreiface.KeyAPI {
40 - return &KeyAPI{
41 - api,
42 - nil,
43 - }
37 + return &KeyAPI{api, nil}
38 }
39
40 func (api *CoreAPI) ResolveNode(ctx context.Context, p coreiface.Path) (coreiface.Node, error) {
core/coreapi/interface/interface.go
+47
@@ -98,26 +98,73 @@ type DagAPI interface {
98 WithDepth(depth int) options.DagTreeOption
99 }
100
101 +// NameAPI specifies the interface to IPNS.
102 +//
103 +// IPNS is a PKI namespace, where names are the hashes of public keys, and the
104 +// private key enables publishing new (signed) values. In both publish and
105 +// resolve, the default name used is the node's own PeerID, which is the hash of
106 +// its public key.
107 +//
108 +// You can use .Key API to list and generate more names and their respective keys.
109 type NameAPI interface {
110 + // Publish announces new IPNS name
111 Publish(ctx context.Context, path Path, opts ...options.NamePublishOption) (*IpnsEntry, error)
112 +
113 + // WithValidTime is an option for Publish which specifies for how long the
114 + // entry will remain valid. Default value is 24h
115 WithValidTime(validTime time.Duration) options.NamePublishOption
116 +
117 + // WithKey is an option for Publish which specifies the key to use for
118 + // publishing. Default value is "self" which is the node's own PeerID.
119 + //
120 + // You can use .Key API to list and generate more names and their respective keys.
121 WithKey(key string) options.NamePublishOption
122
123 + // Resolve attempts to resolve the newest version of the specified name
124 Resolve(ctx context.Context, name string, opts ...options.NameResolveOption) (Path, error)
125 +
126 + // WithRecursive is an option for Resolve which specifies whether to perform a
127 + // recursive lookup. Default value is false
128 WithRecursive(recursive bool) options.NameResolveOption
129 +
130 + // WithLocal is an option for Resolve which specifies if the lookup should be
131 + // offline. Default value is false
132 WithLocal(local bool) options.NameResolveOption
133 +
134 + // WithNoCache is an option for Resolve which specifies when set to true
135 + // disables the use of local name cache. Default value is false
136 WithNoCache(nocache bool) options.NameResolveOption
137 }
138
139 +// KeyAPI specifies the interface to Keystore
140 type KeyAPI interface {
141 + // Generate generates new key, stores it in the keystore under the specified
142 + // name and returns a base58 encoded multihash of it's public key
143 Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (string, error)
144 +
145 + // WithAlgorithm is an option for Generate which specifies which algorithm
146 + // should be used for the key. Default is "rsa"
147 + //
148 + // Supported algorithms:
149 + // * rsa
150 + // * ed25519
151 WithAlgorithm(algorithm string) options.KeyGenerateOption
152 +
153 + // WithSize is an option for Generate which specifies the size of the key to
154 + // generated. Default is 0
155 WithSize(size int) options.KeyGenerateOption
156
157 + // Rename renames oldName key to newName.
158 Rename(ctx context.Context, oldName string, newName string, opts ...options.KeyRenameOption) (string, bool, error)
159 +
160 + // WithForce is an option for Rename which specifies whether to allow to
161 + // replace existing keys.
162 WithForce(force bool) options.KeyRenameOption
163
164 + // List lists keys stored in keystore
165 List(ctx context.Context) (map[string]string, error) //TODO: better key type?
166 +
167 + // Remove removes keys from keystore
168 Remove(ctx context.Context, name string) (string, error)
169 }
170
core/coreapi/key.go
+1 -1
@@ -30,7 +30,7 @@ func (api *KeyAPI) Generate(ctx context.Context, name string, opts ...caopts.Key
30 switch options.Algorithm {
31 case "rsa":
32 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")
34 }
35
36 priv, pub, err := crypto.GenerateKeyPairWithReader(crypto.RSA, options.Size, rand.Reader)