Skip to content

Commit

Permalink
use b36 keys by default for keys and IPNS
Browse files Browse the repository at this point in the history
  • Loading branch information
petar committed Aug 7, 2020
1 parent 18a2756 commit e2f418b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var keyGenCmd = &cmds.Command{
Options: []cmds.Option{
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault("rsa"),
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"),
Expand Down Expand Up @@ -292,7 +292,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 {
Expand Down
34 changes: 17 additions & 17 deletions core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions test/sharness/t0160-resolve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e2f418b

Please sign in to comment.