use b36 keys by default for keys and IPNS
Petar Maymounkov committed
Aug 7, 2020 at 11:55 UTC
3cbe111b2dfc6868ae83075045fdb6d98e28baea
4 files changed
+31
-27
core/commands/keystore.go
+2
-2
@@ -82,7 +82,7 @@ var keyGenCmd = &cmds.Command{
82
Options: []cmds.Option{
83
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault),
84
cmds.IntOption(keyStoreSizeOptionName, "s", "size of the key to generate"),
85
- cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
85
+ cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
86
},
87
Arguments: []cmds.Argument{
88
cmds.StringArg("name", true, false, "name of key to create"),
@@ -298,7 +298,7 @@ var keyListCmd = &cmds.Command{
298
},
299
Options: []cmds.Option{
300
cmds.BoolOption("l", "Show extra information about keys."),
301
- cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"),
301
+ cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"),
302
},
303
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
304
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
core/commands/resolve.go
+17
-17
@@ -82,23 +82,6 @@ Resolve the value of an IPFS DAG path:
82
name := req.Arguments[0]
83
recursive, _ := req.Options[resolveRecursiveOptionName].(bool)
84
85
- var enc cidenc.Encoder
86
- switch {
87
- case !cmdenv.CidBaseDefined(req):
88
- // Not specified, check the path.
89
- enc, err = cmdenv.CidEncoderFromPath(name)
90
- if err == nil {
91
- break
92
- }
93
- // Nope, fallback on the default.
94
- fallthrough
95
- default:
96
- enc, err = cmdenv.GetCidEncoder(req)
97
- if err != nil {
98
- return err
99
- }
100
- }
101
-
85
// the case when ipns is resolved step by step
86
if strings.HasPrefix(name, "/ipns/") && !recursive {
87
rc, rcok := req.Options[resolveDhtRecordCountOptionName].(uint)
@@ -128,6 +111,23 @@ Resolve the value of an IPFS DAG path:
111
return cmds.EmitOnce(res, &ncmd.ResolvedPath{Path: ipfspath.Path(p.String())})
112
}
113
114
+ var enc cidenc.Encoder
115
+ switch {
116
+ case !cmdenv.CidBaseDefined(req) && !strings.HasPrefix(name, "/ipns/"):
117
+ // Not specified, check the path.
118
+ enc, err = cmdenv.CidEncoderFromPath(name)
119
+ if err == nil {
120
+ break
121
+ }
122
+ // Nope, fallback on the default.
123
+ fallthrough
124
+ default:
125
+ enc, err = cmdenv.GetCidEncoder(req)
126
+ if err != nil {
127
+ return err
128
+ }
129
+ }
130
+
131
// else, ipfs path or ipns with recursive flag
132
rp, err := api.ResolvePath(req.Context, path.New(name))
133
if err != nil {
test/sharness/t0160-resolve.sh
+6
-2
@@ -22,8 +22,10 @@ test_expect_success "resolve: prepare dag" '
22
'
23
24
test_expect_success "resolve: prepare keys" '
25
- self_hash=$(ipfs id -f="<id>") &&
26
- alt_hash=$(ipfs key gen -f=b58mh -t rsa alt)
25
+ self_hash=$(ipfs key list -f=b36cid -l | grep self | cut -d " " -f1) &&
26
+ alt_hash=$(ipfs key gen -f=b36cid -t rsa alt)
27
+ echo self_hash $self_hash
28
+ echo $(ipfs id -f="<id>")
29
'
30
31
test_resolve_setup_name() {
@@ -60,6 +62,7 @@ test_resolve() {
62
}
63
64
test_resolve_cmd() {
65
+ echo '-- starting test_resolve_cmd'
66
test_resolve "/ipfs/$a_hash" "/ipfs/$a_hash"
67
test_resolve "/ipfs/$a_hash/b" "/ipfs/$b_hash"
68
test_resolve "/ipfs/$a_hash/b/c" "/ipfs/$c_hash"
@@ -96,6 +99,7 @@ test_resolve_cmd() {
99
}
100
101
test_resolve_cmd_b32() {
102
+ echo '-- starting test_resolve_cmd_b32'
103
# no flags needed, base should be preserved
104
105
test_resolve "/ipfs/$a_hash_b32" "/ipfs/$a_hash_b32"
test/sharness/t0165-keystore.sh
+6
-6
@@ -59,12 +59,12 @@ ipfs key rm key_ed25519
59
60
61
test_expect_success "create a new rsa key" '
62
- rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048)
62
+ rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048 -f=b58mh)
63
echo $rsahash > rsa_key_id
64
'
65
66
test_expect_success "create a new ed25519 key" '
67
- edhash=$(ipfs key gen generated_ed25519_key --type=ed25519)
67
+ edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 -f=b58mh)
68
echo $edhash > ed25519_key_id
69
'
70
@@ -119,13 +119,13 @@ ipfs key rm key_ed25519
119
'
120
121
test_expect_success "key hashes show up in long list output" '
122
- ipfs key list -l | grep $edhash > /dev/null &&
123
- ipfs key list -l | grep $rsahash > /dev/null
122
+ ipfs key list -l -f=b58mh | grep $edhash > /dev/null &&
123
+ ipfs key list -l -f=b58mh | grep $rsahash > /dev/null
124
'
125
126
test_expect_success "key list -l contains self key with peerID" '
127
PeerID="$(ipfs config Identity.PeerID)"
128
- ipfs key list -l | grep "$PeerID\s\+self"
128
+ ipfs key list -l -f=b58mh | grep "$PeerID\s\+self"
129
'
130
131
test_expect_success "key rm remove a key" '
@@ -152,7 +152,7 @@ ipfs key rm key_ed25519
152
'
153
154
test_expect_success "key rename rename key output succeeds" '
155
- key_content=$(ipfs key gen key1 --type=rsa --size=2048) &&
155
+ key_content=$(ipfs key gen key1 --type=rsa --size=2048 -f=b58mh) &&
156
ipfs key rename key1 key2 >rs &&
157
echo "Key $key_content renamed to key2" >expect &&
158
test_cmp rs expect