Commit 3cbe111b authored by Petar Maymounkov's avatar Petar Maymounkov

use b36 keys by default for keys and IPNS

parent 8ae5aa56
......@@ -82,7 +82,7 @@ var keyGenCmd = &cmds.Command{
Options: []cmds.Option{
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
},
Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "name of key to create"),
......@@ -298,7 +298,7 @@ var keyListCmd = &cmds.Command{
},
Options: []cmds.Option{
cmds.BoolOption("l", "Show extra information about keys."),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
......
......@@ -82,23 +82,6 @@ Resolve the value of an IPFS DAG path:
name := req.Arguments[0]
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
}
// the case when ipns is resolved step by step
if strings.HasPrefix(name, "/ipns/") && !recursive {
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
......@@ -128,6 +111,23 @@ Resolve the value of an IPFS DAG path:
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(p.String())})
}
var enc cidenc.Encoder
switch {
case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
// Not specified, check the path.
enc, err = cmdenv.CidEncoderFromPath(name)
if err == nil {
break
}
// Nope, fallback on the default.
fallthrough
default:
enc, err = cmdenv.GetCidEncoder(req)
if err != nil {
return err
}
}
// else, ipfs path or ipns with recursive flag
rp, err := api.ResolvePath(req.Context, path.New(name))
if err != nil {
......
......@@ -22,8 +22,10 @@ test_expect_success "resolve: prepare dag" '
'
test_expect_success "resolve: prepare keys" '
self_hash=$(ipfs id -f="<id>") &&
alt_hash=$(ipfs key gen -f=b58mh -t rsa alt)
self_hash=$(ipfs key list -f=b36cid -l | grep self | cut -d " " -f1) &&
alt_hash=$(ipfs key gen -f=b36cid -t rsa alt)
echo self_hash $self_hash
echo $(ipfs id -f="<id>")
'
test_resolve_setup_name() {
......@@ -60,6 +62,7 @@ test_resolve() {
}
test_resolve_cmd() {
echo '-- starting test_resolve_cmd'
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
......@@ -96,6 +99,7 @@ test_resolve_cmd() {
}
test_resolve_cmd_b32() {
echo '-- starting test_resolve_cmd_b32'
# no flags needed, base should be preserved
test_resolve "/ipfs/$a_hash_b32" "/ipfs/$a_hash_b32"
......
......@@ -59,12 +59,12 @@ ipfs key rm key_ed25519
test_expect_success "create a new rsa key" '
rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048)
rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048 -f=b58mh)
echo $rsahash > rsa_key_id
'
test_expect_success "create a new ed25519 key" '
edhash=$(ipfs key gen generated_ed25519_key --type=ed25519)
edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 -f=b58mh)
echo $edhash > ed25519_key_id
'
......@@ -119,13 +119,13 @@ ipfs key rm key_ed25519
'
test_expect_success "key hashes show up in long list output" '
ipfs key list -l | grep $edhash > /dev/null &&
ipfs key list -l | grep $rsahash > /dev/null
ipfs key list -l -f=b58mh | grep $edhash > /dev/null &&
ipfs key list -l -f=b58mh | grep $rsahash > /dev/null
'
test_expect_success "key list -l contains self key with peerID" '
PeerID="$(ipfs config Identity.PeerID)"
ipfs key list -l | grep "$PeerID\s\+self"
ipfs key list -l -f=b58mh | grep "$PeerID\s\+self"
'
test_expect_success "key rm remove a key" '
......@@ -152,7 +152,7 @@ ipfs key rm key_ed25519
'
test_expect_success "key rename rename key output succeeds" '
key_content=$(ipfs key gen key1 --type=rsa --size=2048) &&
key_content=$(ipfs key gen key1 --type=rsa --size=2048 -f=b58mh) &&
ipfs key rename key1 key2 >rs &&
echo "Key $key_content renamed to key2" >expect &&
test_cmp rs expect
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment