From 3cbe111b2dfc6868ae83075045fdb6d98e28baea Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Fri, 7 Aug 2020 11:55:08 -0700 Subject: [PATCH 1/9] use b36 keys by default for keys and IPNS --- core/commands/keystore.go | 4 ++-- core/commands/resolve.go | 34 ++++++++++++++++----------------- test/sharness/t0160-resolve.sh | 8 ++++++-- test/sharness/t0165-keystore.sh | 12 ++++++------ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/core/commands/keystore.go b/core/commands/keystore.go index b9cbb2af677..de79c30e83d 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -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 { diff --git a/core/commands/resolve.go b/core/commands/resolve.go index da11789590f..63d17504807 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -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 { diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index 6f63d6f31b3..84af288c9e2 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -22,8 +22,10 @@ test_expect_success "resolve: prepare dag" ' ' test_expect_success "resolve: prepare keys" ' - self_hash=$(ipfs id -f="") && - 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="") ' 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" diff --git a/test/sharness/t0165-keystore.sh b/test/sharness/t0165-keystore.sh index 5f346a3d2b8..a64928164c7 100755 --- a/test/sharness/t0165-keystore.sh +++ b/test/sharness/t0165-keystore.sh @@ -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 From a1ae867badcd15527b4cc53ab8c40342247b2016 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Fri, 7 Aug 2020 16:49:02 -0400 Subject: [PATCH 2/9] Namesys cache uses IPNS keys with their binary representation instead of string representation to avoid encoding mismatches --- namesys/namesys.go | 35 ++++++++++++++++++++--------------- namesys/namesys_test.go | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/namesys/namesys.go b/namesys/namesys.go index ac7fb0383f6..760d04c1788 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -122,24 +122,13 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. key := segments[2] - if p, ok := ns.cacheGet(key); ok { - var err error - if len(segments) > 3 { - p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3]) - } - - out <- onceResult{value: p, err: err} - close(out) - return out - } - // Resolver selection: // 1. if it is a PeerID/CID/multihash resolve through "ipns". // 2. if it is a domain name, resolve through "dns" // 3. otherwise resolve through the "proquint" resolver var res resolver - _, err := peer.Decode(key) + ipnsKey, err := peer.Decode(key) // CIDs in IPNS are expected to have libp2p-key multicodec // We ease the transition by returning a more meaningful error with a valid CID @@ -155,6 +144,22 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. } } + cacheKey := key + if err == nil { + cacheKey = string(ipnsKey) + } + + if p, ok := ns.cacheGet(cacheKey); ok { + var err error + if len(segments) > 3 { + p, err = path.FromSegments("", strings.TrimRight(p.String(), "/"), segments[3]) + } + + out <- onceResult{value: p, err: err} + close(out) + return out + } + if err == nil { res = ns.ipnsResolver } else if isd.IsDomain(key) { @@ -172,7 +177,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. case res, ok := <-resCh: if !ok { if best != (onceResult{}) { - ns.cacheSet(key, best.value, best.ttl) + ns.cacheSet(cacheKey, best.value, best.ttl) } return } @@ -218,7 +223,7 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path. if err := ns.ipnsPublisher.PublishWithEOL(ctx, name, value, eol); err != nil { // Invalidate the cache. Publishing may _partially_ succeed but // still return an error. - ns.cacheInvalidate(peer.Encode(id)) + ns.cacheInvalidate(string(id)) return err } ttl := DefaultResolverCacheTTL @@ -228,6 +233,6 @@ func (ns *mpns) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path. if ttEol := time.Until(eol); ttEol < ttl { ttl = ttEol } - ns.cacheSet(peer.Encode(id), value, ttl) + ns.cacheSet(string(id), value, ttl) return nil } diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index b3e963c9e9e..cc0ca69590c 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -155,7 +155,7 @@ func TestPublishWithTTL(t *testing.T) { if err != nil { t.Fatal(err) } - ientry, ok := nsys.(*mpns).cache.Get(pid.Pretty()) + ientry, ok := nsys.(*mpns).cache.Get(string(pid)) if !ok { t.Fatal("cache get failed") } From a7629a27c0c4fdc6f3a07652e6763839edec0ef6 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Mon, 10 Aug 2020 07:58:24 -0700 Subject: [PATCH 3/9] fix rotate sharness --- test/sharness/t0027-rotate.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sharness/t0027-rotate.sh b/test/sharness/t0027-rotate.sh index 683d74420bb..22d4f350e58 100755 --- a/test/sharness/t0027-rotate.sh +++ b/test/sharness/t0027-rotate.sh @@ -56,8 +56,8 @@ test_rotate() { test_expect_success "checking ID" ' ipfs config Identity.PeerID > expected-id && ipfs id -f "\n" > actual-id && - ipfs key list -l | grep self | cut -d " " -f1 > keystore-id && - ipfs key list -l | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && + ipfs key list -l -f=b58mh | grep self | cut -d " " -f1 > keystore-id && + ipfs key list -l -f=b58mh | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && test_cmp expected-id actual-id && test_cmp expected-id keystore-id && test_cmp old-keystore-id first_id From 80e859ef6f29cc2d2023b54c7ca65bae6113a031 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Mon, 10 Aug 2020 12:02:15 -0700 Subject: [PATCH 4/9] add format flag to key rename and remove, defaulting to b36cid; update sharness --- core/commands/keystore.go | 15 +++++++++++++-- test/sharness/t0165-keystore.sh | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/commands/keystore.go b/core/commands/keystore.go index de79c30e83d..a15e14aa013 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -346,12 +346,16 @@ var keyRenameCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."), + cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } + if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + return err + } name := req.Arguments[0] newName := req.Arguments[1] @@ -365,7 +369,7 @@ var keyRenameCmd = &cmds.Command{ return cmds.EmitOnce(res, &KeyRenameOutput{ Was: name, Now: newName, - Id: key.ID().Pretty(), + Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(), Overwrite: overwritten, }) }, @@ -391,12 +395,16 @@ var keyRmCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), + cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } + if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + return err + } names := req.Arguments @@ -407,7 +415,10 @@ var keyRmCmd = &cmds.Command{ return err } - list = append(list, KeyOutput{Name: name, Id: key.ID().Pretty()}) + list = append(list, KeyOutput{ + Name: name, + Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(), + }) } return cmds.EmitOnce(res, &KeyOutputList{list}) diff --git a/test/sharness/t0165-keystore.sh b/test/sharness/t0165-keystore.sh index a64928164c7..1eaf5559048 100755 --- a/test/sharness/t0165-keystore.sh +++ b/test/sharness/t0165-keystore.sh @@ -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 -f=b58mh) && + key_content=$(ipfs key gen key1 --type=rsa --size=2048) && ipfs key rename key1 key2 >rs && echo "Key $key_content renamed to key2" >expect && test_cmp rs expect From 23a26c05d3d66d80113eee76201cb8fd0e00c280 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Mon, 10 Aug 2020 21:45:02 -0700 Subject: [PATCH 5/9] rename -f to --ipns-base --- core/commands/keystore.go | 20 +++++++------- test/sharness/t0027-rotate.sh | 4 +-- test/sharness/t0100-name.sh | 16 ++++++------ test/sharness/t0114-gateway-subdomains.sh | 6 ++--- test/sharness/t0160-resolve.sh | 4 +-- test/sharness/t0165-keystore.sh | 26 +++++++++---------- .../t0600-issues-and-regressions-online.sh | 2 +- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/commands/keystore.go b/core/commands/keystore.go index a15e14aa013..9935c589496 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -68,11 +68,11 @@ type KeyRenameOutput struct { } const ( - keyStoreAlgorithmDefault = options.RSAKey - keyStoreTypeOptionName = "type" - keyStoreSizeOptionName = "size" - keyFormatOptionName = "format" - oldKeyOptionName = "oldkey" + keyStoreAlgorithmDefault = options.RSAKey + keyStoreTypeOptionName = "type" + keyStoreSizeOptionName = "size" + keyFormatOptionName = "ipns-base" + oldKeyOptionName = "oldkey" ) var keyGenCmd = &cmds.Command{ @@ -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("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name of key to create"), @@ -223,7 +223,7 @@ var keyImportCmd = &cmds.Command{ Tagline: "Import a key and prints imported key id", }, Options: []cmds.Option{ - cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b58mh"), + cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b58mh"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name to associate with key in keychain"), @@ -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("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "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 { @@ -395,7 +395,7 @@ var keyRmCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(keyFormatOptionName, "f", "output format: b58mh or b36cid").WithDefault("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) @@ -417,7 +417,7 @@ var keyRmCmd = &cmds.Command{ list = append(list, KeyOutput{ Name: name, - Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(), + Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), }) } diff --git a/test/sharness/t0027-rotate.sh b/test/sharness/t0027-rotate.sh index 22d4f350e58..2c67bd1f085 100755 --- a/test/sharness/t0027-rotate.sh +++ b/test/sharness/t0027-rotate.sh @@ -56,8 +56,8 @@ test_rotate() { test_expect_success "checking ID" ' ipfs config Identity.PeerID > expected-id && ipfs id -f "\n" > actual-id && - ipfs key list -l -f=b58mh | grep self | cut -d " " -f1 > keystore-id && - ipfs key list -l -f=b58mh | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && + ipfs key list -l --ipns-base=b58mh | grep self | cut -d " " -f1 > keystore-id && + ipfs key list -l --ipns-base=b58mh | grep oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id && test_cmp expected-id actual-id && test_cmp expected-id keystore-id && test_cmp old-keystore-id first_id diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index f2088ee8220..e617d5070a9 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -24,7 +24,7 @@ test_name_with_self() { ipfs init --profile=test -a=ed25519 > /dev/null ;; esac && - export PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` && + export PEERID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && test_check_peerid "${PEERID}" ' @@ -109,8 +109,8 @@ test_name_with_self() { # test publishing with B36CID and B58MH resolve to the same B36CID test_expect_success "verify self key output" ' - B58MH_ID=`ipfs key list -f=b58mh -l | grep self | cut -d " " -f1` && - B36CID_ID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` && + B58MH_ID=`ipfs key list --ipns-base=b58mh -l | grep self | cut -d " " -f1` && + B36CID_ID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && test_check_peerid "${B58MH_ID}" && test_check_peerid "${B36CID_ID}" ' @@ -250,15 +250,15 @@ test_name_with_key() { test_expect_success "'prepare keys" ' case $GEN_ALG in rsa) - export KEY=`ipfs key gen -f=b58mh --type=rsa --size=2048 key` && - export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1` + export KEY=`ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key` && + export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1` ;; ed25519_b58) - export KEY=`ipfs key gen -f=b58mh --type=ed25519 key` - export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1` + export KEY=`ipfs key gen --ipns-base=b58mh --type=ed25519 key` + export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1` ;; ed25519_b36) - export KEY=`ipfs key gen -f=b36cid --type=ed25519 key` + export KEY=`ipfs key gen --ipns-base=b36cid --type=ed25519 key` export KEY_B36CID=$KEY ;; esac && diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 5f3020346ef..8d94eb9c483 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -113,7 +113,7 @@ test_expect_success "Add the test directory" ' ' test_expect_success "Publish test text file to IPNS using RSA keys" ' - RSA_KEY=$(ipfs key gen -f=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n") + RSA_KEY=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 test_key_rsa | head -n1 | tr -d "\n") RSA_IPNS_IDv0=$(echo "$RSA_KEY" | ipfs cid format -v 0) RSA_IPNS_IDv1=$(echo "$RSA_KEY" | ipfs cid format -v 1 --codec libp2p-key -b base36) RSA_IPNS_IDv1_DAGPB=$(echo "$RSA_IPNS_IDv0" | ipfs cid format -v 1 -b base36) @@ -125,9 +125,9 @@ test_expect_success "Publish test text file to IPNS using RSA keys" ' ' test_expect_success "Publish test text file to IPNS using ED25519 keys" ' - ED25519_KEY=$(ipfs key gen -f=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n") + ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n") ED25519_IPNS_IDv0=$ED25519_KEY - ED25519_IPNS_IDv1=$(ipfs key list -l -f b36cid | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n") + ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=b36cid | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n") ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --codec protobuf) test_check_peerid "${ED25519_KEY}" && ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out && diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index 84af288c9e2..4f67ac5a900 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -22,8 +22,8 @@ test_expect_success "resolve: prepare dag" ' ' test_expect_success "resolve: prepare keys" ' - self_hash=$(ipfs key list -f=b36cid -l | grep self | cut -d " " -f1) && - alt_hash=$(ipfs key gen -f=b36cid -t rsa alt) + self_hash=$(ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1) && + alt_hash=$(ipfs key gen --ipns-base=b36cid -t rsa alt) echo self_hash $self_hash echo $(ipfs id -f="") ' diff --git a/test/sharness/t0165-keystore.sh b/test/sharness/t0165-keystore.sh index 1eaf5559048..5aafd9fb608 100755 --- a/test/sharness/t0165-keystore.sh +++ b/test/sharness/t0165-keystore.sh @@ -13,10 +13,10 @@ test_init_ipfs test_key_cmd() { # test key output format test_expect_success "create an RSA key and test B58MH/B36CID output formats" ' -PEERID=$(ipfs key gen -f=b58mh --type=rsa --size=2048 key_rsa) && +PEERID=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key_rsa) && test_check_rsa2048_b58mh_peerid $PEERID && ipfs key rm key_rsa && -PEERID=$(ipfs key gen -f=b36cid --type=rsa --size=2048 key_rsa) && +PEERID=$(ipfs key gen --ipns-base=b36cid --type=rsa --size=2048 key_rsa) && test_check_rsa2048_b36cid_peerid $PEERID ' @@ -27,18 +27,18 @@ rm key_rsa.key ' test_expect_success "test RSA key B58MH/B36CID multihash format" ' -PEERID=$(ipfs key list -f=b58mh -l | grep key_rsa | head -n 1 | cut -d " " -f1) && +PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_rsa | head -n 1 | cut -d " " -f1) && test_check_rsa2048_b58mh_peerid $PEERID && -PEERID=$(ipfs key list -f=b36cid -l | grep key_rsa | head -n 1 | cut -d " " -f1) && +PEERID=$(ipfs key list --ipns-base=b36cid -l | grep key_rsa | head -n 1 | cut -d " " -f1) && test_check_rsa2048_b36cid_peerid $PEERID && ipfs key rm key_rsa ' test_expect_success "create an ED25519 key and test B58MH/B36CID output formats" ' -PEERID=$(ipfs key gen -f=b58mh --type=ed25519 key_ed25519) && +PEERID=$(ipfs key gen --ipns-base=b58mh --type=ed25519 key_ed25519) && test_check_ed25519_b58mh_peerid $PEERID && ipfs key rm key_ed25519 && -PEERID=$(ipfs key gen -f=b36cid --type=ed25519 key_ed25519) && +PEERID=$(ipfs key gen --ipns-base=b36cid --type=ed25519 key_ed25519) && test_check_ed25519_b36cid_peerid $PEERID ' @@ -49,9 +49,9 @@ rm key_ed25519.key ' test_expect_success "test ED25519 key B58MH/B36CID multihash format" ' -PEERID=$(ipfs key list -f=b58mh -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && +PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && test_check_ed25519_b58mh_peerid $PEERID && -PEERID=$(ipfs key list -f=b36cid -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && +PEERID=$(ipfs key list --ipns-base=b36cid -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && test_check_ed25519_b36cid_peerid $PEERID && ipfs key rm key_ed25519 ' @@ -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 -f=b58mh) + rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048 --ipns-base=b58mh) echo $rsahash > rsa_key_id ' test_expect_success "create a new ed25519 key" ' - edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 -f=b58mh) + edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 --ipns-base=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 -f=b58mh | grep $edhash > /dev/null && - ipfs key list -l -f=b58mh | grep $rsahash > /dev/null + ipfs key list -l --ipns-base=b58mh | grep $edhash > /dev/null && + ipfs key list -l --ipns-base=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 -f=b58mh | grep "$PeerID\s\+self" + ipfs key list -l --ipns-base=b58mh | grep "$PeerID\s\+self" ' test_expect_success "key rm remove a key" ' diff --git a/test/sharness/t0600-issues-and-regressions-online.sh b/test/sharness/t0600-issues-and-regressions-online.sh index 3343df1208c..07b90f7562a 100755 --- a/test/sharness/t0600-issues-and-regressions-online.sh +++ b/test/sharness/t0600-issues-and-regressions-online.sh @@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" ' test_launch_ipfs_daemon --offline test_expect_success "'ipfs name resolve' succeeds after ipfs id when daemon offline" ' - PEERID=`ipfs key list -f=b36cid -l | grep self | cut -d " " -f1` && + PEERID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && test_check_peerid "${PEERID}" && ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out ' From 2b013a1ac52d33c1f0be77c70b5e892c39eaa466 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Tue, 11 Aug 2020 08:42:54 -0700 Subject: [PATCH 6/9] use standard multibase format labels --- core/commands/keybase/keybase.go | 35 +++++++++ core/commands/keystore.go | 74 ++++++++++++------- test/sharness/lib/test-lib.sh | 8 +- test/sharness/t0100-name.sh | 14 ++-- test/sharness/t0114-gateway-subdomains.sh | 2 +- test/sharness/t0160-resolve.sh | 6 +- test/sharness/t0165-keystore.sh | 16 ++-- .../t0600-issues-and-regressions-online.sh | 2 +- 8 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 core/commands/keybase/keybase.go diff --git a/core/commands/keybase/keybase.go b/core/commands/keybase/keybase.go new file mode 100644 index 00000000000..b857c8dbb99 --- /dev/null +++ b/core/commands/keybase/keybase.go @@ -0,0 +1,35 @@ +package keybase + +import ( + peer "github.com/libp2p/go-libp2p-core/peer" + mbase "github.com/multiformats/go-multibase" +) + +type KeyEncoder struct { + baseEnc *mbase.Encoder +} + +func KeyEncoderFromString(formatLabel string) (KeyEncoder, error) { + switch formatLabel { + case "b58mh", "v0": + return KeyEncoder{}, nil + default: + if enc, err := mbase.EncoderByName(formatLabel); err != nil { + return KeyEncoder{}, err + } else { + return KeyEncoder{&enc}, nil + } + } +} + +func (enc KeyEncoder) FormatID(id peer.ID) string { + if enc.baseEnc == nil { + //nolint deprecated + return peer.IDB58Encode(id) + } + if s, err := peer.ToCid(id).StringOfBase(enc.baseEnc.Encoding()); err != nil { + panic(err) + } else { + return s + } +} diff --git a/core/commands/keystore.go b/core/commands/keystore.go index 9935c589496..f78bafa20bc 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -15,6 +15,7 @@ import ( oldcmds "github.com/ipfs/go-ipfs/commands" cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" "github.com/ipfs/go-ipfs/core/commands/e" + kb "github.com/ipfs/go-ipfs/core/commands/keybase" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" options "github.com/ipfs/interface-go-ipfs-core/options" "github.com/libp2p/go-libp2p-core/crypto" @@ -82,7 +83,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, "", "output format: b58mh or b36cid").WithDefault("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name of key to create"), @@ -109,7 +110,8 @@ var keyGenCmd = &cmds.Command{ if sizefound { opts = append(opts, options.Key.Size(size)) } - if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + if err != nil { return err } @@ -121,7 +123,7 @@ var keyGenCmd = &cmds.Command{ return cmds.EmitOnce(res, &KeyOutput{ Name: name, - Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), + Id: keyEnc.FormatID(key.ID()), }) }, Encoders: cmds.EncoderMap{ @@ -223,7 +225,7 @@ var keyImportCmd = &cmds.Command{ Tagline: "Import a key and prints imported key id", }, Options: []cmds.Option{ - cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b58mh"), + cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name to associate with key in keychain"), @@ -236,6 +238,11 @@ var keyImportCmd = &cmds.Command{ return fmt.Errorf("cannot import key with name 'self'") } + keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + if err != nil { + return err + } + file, err := cmdenv.GetFileArg(req.Files.Entries()) if err != nil { return err @@ -280,7 +287,7 @@ var keyImportCmd = &cmds.Command{ return cmds.EmitOnce(res, &KeyOutput{ Name: name, - Id: formatID(pid, req.Options[keyFormatOptionName].(string)), + Id: keyEnc.FormatID(pid), }) }, Encoders: cmds.EncoderMap{ @@ -298,10 +305,11 @@ var keyListCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + if err != nil { return err } @@ -320,7 +328,7 @@ var keyListCmd = &cmds.Command{ for _, key := range keys { list = append(list, KeyOutput{ Name: key.Name(), - Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), + Id: keyEnc.FormatID(key.ID()), }) } @@ -346,14 +354,15 @@ var keyRenameCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."), - cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + if err != nil { return err } @@ -369,7 +378,7 @@ var keyRenameCmd = &cmds.Command{ return cmds.EmitOnce(res, &KeyRenameOutput{ Was: name, Now: newName, - Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(), + Id: keyEnc.FormatID(key.ID()), Overwrite: overwritten, }) }, @@ -395,14 +404,15 @@ var keyRmCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(keyFormatOptionName, "", "output format: b58mh or b36cid").WithDefault("b36cid"), + cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - if err = verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { + keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + if err != nil { return err } @@ -417,7 +427,7 @@ var keyRmCmd = &cmds.Command{ list = append(list, KeyOutput{ Name: name, - Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), + Id: keyEnc.FormatID(key.ID()), }) } @@ -530,26 +540,36 @@ func doRotate(out io.Writer, repoRoot string, oldKey string, algorithm string, n func verifyIDFormatLabel(formatLabel string) error { switch formatLabel { - case "b58mh": - return nil - case "b36cid": + case "b58mh", "v0": return nil + default: + _, err := mbase.EncoderByName(formatLabel) + return err } - return fmt.Errorf("invalid output format option") } -func formatID(id peer.ID, formatLabel string) string { +func keyEncoderFromString(formatLabel string) (keyEncoder, error) { switch formatLabel { - case "b58mh": - return id.Pretty() - case "b36cid": - if s, err := peer.ToCid(id).StringOfBase(mbase.Base36); err != nil { - panic(err) + case "b58mh", "v0": + return keyEncoder{}, nil + default: + if enc, err := mbase.EncoderByName(formatLabel); err != nil { + return keyEncoder{}, err } else { - return s + return keyEncoder{&enc}, nil } - default: - panic("unreachable") + } +} + +func (enc keyEncoder) FormatID(id peer.ID) string { + if enc.baseEnc == nil { + //nolint deprecated + return peer.IDB58Encode(id) + } + if s, err := peer.ToCid(id).StringOfBase(enc.baseEnc.Encoding()); err != nil { + panic(err) + } else { + return s } } diff --git a/test/sharness/lib/test-lib.sh b/test/sharness/lib/test-lib.sh index 6eac7a2e189..e67f56d4b4a 100644 --- a/test/sharness/lib/test-lib.sh +++ b/test/sharness/lib/test-lib.sh @@ -445,8 +445,8 @@ file_size() { # len 46: 2048-bit RSA keys, b58mh-encoded # len 52: ED25519 keys, b58mh-encoded -# len 56: 2048-bit RSA keys, b36cid-encoded -# len 62: ED25519 keys, b36cid-encoded +# len 56: 2048-bit RSA keys, base36-encoded +# len 62: ED25519 keys, base36-encoded test_check_peerid() { peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") && test "$peeridlen" = "46" -o "$peeridlen" = "52" -o "$peeridlen" = "56" -o "$peeridlen" = "62" || { @@ -471,7 +471,7 @@ test_check_ed25519_b58mh_peerid() { } } -test_check_rsa2048_b36cid_peerid() { +test_check_rsa2048_base36_peerid() { peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") && test "$peeridlen" = "56" || { echo "Bad RSA2048 B36CID peerid '$1' with len '$peeridlen'" @@ -479,7 +479,7 @@ test_check_rsa2048_b36cid_peerid() { } } -test_check_ed25519_b36cid_peerid() { +test_check_ed25519_base36_peerid() { peeridlen=$(echo "$1" | tr -dC "[:alnum:]" | wc -c | tr -d " ") && test "$peeridlen" = "62" || { echo "Bad ED25519 B36CID peerid '$1' with len '$peeridlen'" diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index e617d5070a9..9b7a60cd40e 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -24,7 +24,7 @@ test_name_with_self() { ipfs init --profile=test -a=ed25519 > /dev/null ;; esac && - export PEERID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && + export PEERID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` && test_check_peerid "${PEERID}" ' @@ -110,20 +110,20 @@ test_name_with_self() { test_expect_success "verify self key output" ' B58MH_ID=`ipfs key list --ipns-base=b58mh -l | grep self | cut -d " " -f1` && - B36CID_ID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && + B36CID_ID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` && test_check_peerid "${B58MH_ID}" && test_check_peerid "${B36CID_ID}" ' test_expect_success "'ipfs name publish --allow-offline --key= ' succeeds" ' ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id && - ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >b36cid_published_id + ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id ' test_expect_success "publish an explicit node ID as two key in B58MH and B36CID, name looks good" ' echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id && test_cmp expected_published_id b58mh_published_id && - test_cmp expected_published_id b36cid_published_id + test_cmp expected_published_id base36_published_id ' test_expect_success "'ipfs name resolve' succeeds" ' @@ -251,14 +251,14 @@ test_name_with_key() { case $GEN_ALG in rsa) export KEY=`ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key` && - export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1` + export KEY_B36CID=`ipfs key list --ipns-base=base36 -l | grep key | cut -d " " -f1` ;; ed25519_b58) export KEY=`ipfs key gen --ipns-base=b58mh --type=ed25519 key` - export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1` + export KEY_B36CID=`ipfs key list --ipns-base=base36 -l | grep key | cut -d " " -f1` ;; ed25519_b36) - export KEY=`ipfs key gen --ipns-base=b36cid --type=ed25519 key` + export KEY=`ipfs key gen --ipns-base=base36 --type=ed25519 key` export KEY_B36CID=$KEY ;; esac && diff --git a/test/sharness/t0114-gateway-subdomains.sh b/test/sharness/t0114-gateway-subdomains.sh index 8d94eb9c483..19a040b5124 100755 --- a/test/sharness/t0114-gateway-subdomains.sh +++ b/test/sharness/t0114-gateway-subdomains.sh @@ -127,7 +127,7 @@ test_expect_success "Publish test text file to IPNS using RSA keys" ' test_expect_success "Publish test text file to IPNS using ED25519 keys" ' ED25519_KEY=$(ipfs key gen --ipns-base=b58mh --type=ed25519 test_key_ed25519 | head -n1 | tr -d "\n") ED25519_IPNS_IDv0=$ED25519_KEY - ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=b36cid | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n") + ED25519_IPNS_IDv1=$(ipfs key list -l --ipns-base=base36 | grep test_key_ed25519 | cut -d " " -f1 | tr -d "\n") ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --codec protobuf) test_check_peerid "${ED25519_KEY}" && ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out && diff --git a/test/sharness/t0160-resolve.sh b/test/sharness/t0160-resolve.sh index 4f67ac5a900..b460bae7f0a 100755 --- a/test/sharness/t0160-resolve.sh +++ b/test/sharness/t0160-resolve.sh @@ -22,10 +22,8 @@ test_expect_success "resolve: prepare dag" ' ' test_expect_success "resolve: prepare keys" ' - self_hash=$(ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1) && - alt_hash=$(ipfs key gen --ipns-base=b36cid -t rsa alt) - echo self_hash $self_hash - echo $(ipfs id -f="") + self_hash=$(ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1) && + alt_hash=$(ipfs key gen --ipns-base=base36 -t rsa alt) ' test_resolve_setup_name() { diff --git a/test/sharness/t0165-keystore.sh b/test/sharness/t0165-keystore.sh index 5aafd9fb608..e981162f350 100755 --- a/test/sharness/t0165-keystore.sh +++ b/test/sharness/t0165-keystore.sh @@ -16,8 +16,8 @@ test_expect_success "create an RSA key and test B58MH/B36CID output formats" ' PEERID=$(ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key_rsa) && test_check_rsa2048_b58mh_peerid $PEERID && ipfs key rm key_rsa && -PEERID=$(ipfs key gen --ipns-base=b36cid --type=rsa --size=2048 key_rsa) && -test_check_rsa2048_b36cid_peerid $PEERID +PEERID=$(ipfs key gen --ipns-base=base36 --type=rsa --size=2048 key_rsa) && +test_check_rsa2048_base36_peerid $PEERID ' test_expect_success "test RSA key sk export format" ' @@ -29,8 +29,8 @@ rm key_rsa.key test_expect_success "test RSA key B58MH/B36CID multihash format" ' PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_rsa | head -n 1 | cut -d " " -f1) && test_check_rsa2048_b58mh_peerid $PEERID && -PEERID=$(ipfs key list --ipns-base=b36cid -l | grep key_rsa | head -n 1 | cut -d " " -f1) && -test_check_rsa2048_b36cid_peerid $PEERID && +PEERID=$(ipfs key list --ipns-base=base36 -l | grep key_rsa | head -n 1 | cut -d " " -f1) && +test_check_rsa2048_base36_peerid $PEERID && ipfs key rm key_rsa ' @@ -38,8 +38,8 @@ test_expect_success "create an ED25519 key and test B58MH/B36CID output formats" PEERID=$(ipfs key gen --ipns-base=b58mh --type=ed25519 key_ed25519) && test_check_ed25519_b58mh_peerid $PEERID && ipfs key rm key_ed25519 && -PEERID=$(ipfs key gen --ipns-base=b36cid --type=ed25519 key_ed25519) && -test_check_ed25519_b36cid_peerid $PEERID +PEERID=$(ipfs key gen --ipns-base=base36 --type=ed25519 key_ed25519) && +test_check_ed25519_base36_peerid $PEERID ' test_expect_success "test ED25519 key sk export format" ' @@ -51,8 +51,8 @@ rm key_ed25519.key test_expect_success "test ED25519 key B58MH/B36CID multihash format" ' PEERID=$(ipfs key list --ipns-base=b58mh -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && test_check_ed25519_b58mh_peerid $PEERID && -PEERID=$(ipfs key list --ipns-base=b36cid -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && -test_check_ed25519_b36cid_peerid $PEERID && +PEERID=$(ipfs key list --ipns-base=base36 -l | grep key_ed25519 | head -n 1 | cut -d " " -f1) && +test_check_ed25519_base36_peerid $PEERID && ipfs key rm key_ed25519 ' # end of format test diff --git a/test/sharness/t0600-issues-and-regressions-online.sh b/test/sharness/t0600-issues-and-regressions-online.sh index 07b90f7562a..93f51caeecb 100755 --- a/test/sharness/t0600-issues-and-regressions-online.sh +++ b/test/sharness/t0600-issues-and-regressions-online.sh @@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" ' test_launch_ipfs_daemon --offline test_expect_success "'ipfs name resolve' succeeds after ipfs id when daemon offline" ' - PEERID=`ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1` && + PEERID=`ipfs key list --ipns-base=base36 -l | grep self | cut -d " " -f1` && test_check_peerid "${PEERID}" && ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out ' From 3e25355eeb9f5e7f2a8f47fa0b56bd0001f1997a Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Tue, 11 Aug 2020 17:47:10 -0700 Subject: [PATCH 7/9] fix keystore sharness default case --- test/sharness/t0165-keystore.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/sharness/t0165-keystore.sh b/test/sharness/t0165-keystore.sh index e981162f350..07a9ad9fe8e 100755 --- a/test/sharness/t0165-keystore.sh +++ b/test/sharness/t0165-keystore.sh @@ -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 --ipns-base=b58mh) + rsahash=$(ipfs key gen generated_rsa_key --type=rsa --size=2048) echo $rsahash > rsa_key_id ' test_expect_success "create a new ed25519 key" ' - edhash=$(ipfs key gen generated_ed25519_key --type=ed25519 --ipns-base=b58mh) + edhash=$(ipfs key gen generated_ed25519_key --type=ed25519) echo $edhash > ed25519_key_id ' @@ -119,8 +119,8 @@ ipfs key rm key_ed25519 ' test_expect_success "key hashes show up in long list output" ' - ipfs key list -l --ipns-base=b58mh | grep $edhash > /dev/null && - ipfs key list -l --ipns-base=b58mh | grep $rsahash > /dev/null + ipfs key list -l | grep $edhash > /dev/null && + ipfs key list -l | grep $rsahash > /dev/null ' test_expect_success "key list -l contains self key with peerID" ' From b4ad66eda42c9da24926d955c39ac242ac9b74e1 Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Mon, 17 Aug 2020 09:46:51 -0700 Subject: [PATCH 8/9] add --ipns-base to publish and subs commands add sharness tests for --ipns-base in name publish and subs commands --- core/commands/keybase/keybase.go | 2 + core/commands/keystore.go | 57 +++++---------------------- core/commands/name/ipnsps.go | 15 +++++-- core/commands/name/publish.go | 15 ++++++- test/sharness/t0100-name.sh | 15 ++++--- test/sharness/t0183-namesys-pubsub.sh | 26 +++++++----- 6 files changed, 64 insertions(+), 66 deletions(-) diff --git a/core/commands/keybase/keybase.go b/core/commands/keybase/keybase.go index b857c8dbb99..dbc1413e888 100644 --- a/core/commands/keybase/keybase.go +++ b/core/commands/keybase/keybase.go @@ -5,6 +5,8 @@ import ( mbase "github.com/multiformats/go-multibase" ) +const KeyFormatOptionName = "ipns-base" + type KeyEncoder struct { baseEnc *mbase.Encoder } diff --git a/core/commands/keystore.go b/core/commands/keystore.go index f78bafa20bc..7aefcd37674 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -20,7 +20,6 @@ import ( options "github.com/ipfs/interface-go-ipfs-core/options" "github.com/libp2p/go-libp2p-core/crypto" peer "github.com/libp2p/go-libp2p-core/peer" - mbase "github.com/multiformats/go-multibase" ) var KeyCmd = &cmds.Command{ @@ -72,7 +71,6 @@ const ( keyStoreAlgorithmDefault = options.RSAKey keyStoreTypeOptionName = "type" keyStoreSizeOptionName = "size" - keyFormatOptionName = "ipns-base" oldKeyOptionName = "oldkey" ) @@ -83,7 +81,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, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name of key to create"), @@ -110,7 +108,7 @@ var keyGenCmd = &cmds.Command{ if sizefound { opts = append(opts, options.Key.Size(size)) } - keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) if err != nil { return err } @@ -225,7 +223,7 @@ var keyImportCmd = &cmds.Command{ Tagline: "Import a key and prints imported key id", }, Options: []cmds.Option{ - cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name to associate with key in keychain"), @@ -238,7 +236,7 @@ var keyImportCmd = &cmds.Command{ return fmt.Errorf("cannot import key with name 'self'") } - keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) if err != nil { return err } @@ -305,10 +303,10 @@ var keyListCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) if err != nil { return err } @@ -354,14 +352,14 @@ var keyRenameCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."), - cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) if err != nil { return err } @@ -404,14 +402,14 @@ var keyRmCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(keyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - keyEnc, err := kb.KeyEncoderFromString(req.Options[keyFormatOptionName].(string)) + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) if err != nil { return err } @@ -538,41 +536,6 @@ func doRotate(out io.Writer, repoRoot string, oldKey string, algorithm string, n return nil } -func verifyIDFormatLabel(formatLabel string) error { - switch formatLabel { - case "b58mh", "v0": - return nil - default: - _, err := mbase.EncoderByName(formatLabel) - return err - } -} - -func keyEncoderFromString(formatLabel string) (keyEncoder, error) { - switch formatLabel { - case "b58mh", "v0": - return keyEncoder{}, nil - default: - if enc, err := mbase.EncoderByName(formatLabel); err != nil { - return keyEncoder{}, err - } else { - return keyEncoder{&enc}, nil - } - } -} - -func (enc keyEncoder) FormatID(id peer.ID) string { - if enc.baseEnc == nil { - //nolint deprecated - return peer.IDB58Encode(id) - } - if s, err := peer.ToCid(id).StringOfBase(enc.baseEnc.Encoding()); err != nil { - panic(err) - } else { - return s - } -} - func keyOutputListEncoders() cmds.EncoderFunc { return cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, list *KeyOutputList) error { withID, _ := req.Options["l"].(bool) diff --git a/core/commands/name/ipnsps.go b/core/commands/name/ipnsps.go index 3511bed4aa7..ceb742aadd6 100644 --- a/core/commands/name/ipnsps.go +++ b/core/commands/name/ipnsps.go @@ -5,10 +5,11 @@ import ( "io" "strings" - "github.com/ipfs/go-ipfs-cmds" + cmds "github.com/ipfs/go-ipfs-cmds" "github.com/ipfs/go-ipfs/core/commands/cmdenv" + kb "github.com/ipfs/go-ipfs/core/commands/keybase" "github.com/libp2p/go-libp2p-core/peer" - "github.com/libp2p/go-libp2p-record" + record "github.com/libp2p/go-libp2p-record" ) type ipnsPubsubState struct { @@ -72,7 +73,15 @@ var ipnspsSubsCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Show current name subscriptions", }, + Options: []cmds.Option{ + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + if err != nil { + return err + } + n, err := cmdenv.GetNode(env) if err != nil { return err @@ -93,7 +102,7 @@ var ipnspsSubsCmd = &cmds.Command{ log.Errorf("ipns key not a valid peer ID: %s", err) continue } - paths = append(paths, "/ipns/"+peer.Encode(pid)) + paths = append(paths, "/ipns/"+keyEnc.FormatID(pid)) } return cmds.EmitOnce(res, &stringList{paths}) diff --git a/core/commands/name/publish.go b/core/commands/name/publish.go index 6e8cf19c2bd..096eb8a9c1b 100644 --- a/core/commands/name/publish.go +++ b/core/commands/name/publish.go @@ -9,9 +9,11 @@ import ( cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" cmds "github.com/ipfs/go-ipfs-cmds" + kb "github.com/ipfs/go-ipfs/core/commands/keybase" iface "github.com/ipfs/interface-go-ipfs-core" options "github.com/ipfs/interface-go-ipfs-core/options" path "github.com/ipfs/interface-go-ipfs-core/path" + peer "github.com/libp2p/go-libp2p-core/peer" ) var ( @@ -81,12 +83,17 @@ Alternatively, publish an using a valid PeerID (as listed by cmds.StringOption(ttlOptionName, "Time duration this record should be cached for. Uses the same syntax as the lifetime option. (caution: experimental)"), cmds.StringOption(keyOptionName, "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'.").WithDefault("self"), cmds.BoolOption(quieterOptionName, "Q", "Write only final hash."), + cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } + keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + if err != nil { + return err + } allowOffline, _ := req.Options[allowOfflineOptionName].(bool) kname, _ := req.Options[keyOptionName].(string) @@ -129,8 +136,14 @@ Alternatively, publish an using a valid PeerID (as listed by return err } + // parse path, extract cid, re-base cid, reconstruct path + pid, err := peer.Decode(out.Name()) + if err != nil { + return err + } + return cmds.EmitOnce(res, &IpnsEntry{ - Name: out.Name(), + Name: keyEnc.FormatID(pid), Value: out.Value().String(), }) }, diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index 9b7a60cd40e..df55731e9bf 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -116,14 +116,19 @@ test_name_with_self() { ' test_expect_success "'ipfs name publish --allow-offline --key= ' succeeds" ' - ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id && - ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id + ipfs name publish --allow-offline --key=${B58MH_ID} "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id_base36 && + ipfs name publish --allow-offline --key=${B36CID_ID} "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id_base36 && + ipfs name publish --allow-offline --key=${B58MH_ID} --ipns-base=b58mh "/ipfs/$HASH_WELCOME_DOCS" >b58mh_published_id_b58mh && + ipfs name publish --allow-offline --key=${B36CID_ID} --ipns-base=b58mh "/ipfs/$HASH_WELCOME_DOCS" >base36_published_id_b58mh ' test_expect_success "publish an explicit node ID as two key in B58MH and B36CID, name looks good" ' - echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id && - test_cmp expected_published_id b58mh_published_id && - test_cmp expected_published_id base36_published_id + echo "Published to ${B36CID_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id_base36 && + echo "Published to ${B58MH_ID}: /ipfs/$HASH_WELCOME_DOCS" >expected_published_id_b58mh && + test_cmp expected_published_id_base36 b58mh_published_id_base36 && + test_cmp expected_published_id_base36 base36_published_id_base36 && + test_cmp expected_published_id_b58mh b58mh_published_id_b58mh && + test_cmp expected_published_id_b58mh base36_published_id_b58mh ' test_expect_success "'ipfs name resolve' succeeds" ' diff --git a/test/sharness/t0183-namesys-pubsub.sh b/test/sharness/t0183-namesys-pubsub.sh index 1026b47e7c8..8161330c819 100755 --- a/test/sharness/t0183-namesys-pubsub.sh +++ b/test/sharness/t0183-namesys-pubsub.sh @@ -13,7 +13,8 @@ test_expect_success 'init iptb' ' startup_cluster $NUM_NODES --enable-namesys-pubsub test_expect_success 'peer ids' ' - PEERID_0=$(iptb attr get 0 id) + PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) && + PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1) ' test_expect_success 'check namesys pubsub state' ' @@ -28,17 +29,22 @@ test_expect_success 'check namesys pubsub state' ' # These commands are *expected* to fail. We haven't published anything yet. test_expect_success 'subscribe nodes to the publisher topic' ' - ipfsi 1 name resolve /ipns/$PEERID_0 --timeout=1s; - ipfsi 2 name resolve /ipns/$PEERID_0 --timeout=1s; + ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s; + ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s; true ' test_expect_success 'check subscriptions' ' - echo /ipns/$PEERID_0 > expected && + echo /ipns/$PEERID_0_BASE36 > expected_base36 && + echo /ipns/$PEERID_0_B58MH > expected_b58mh && ipfsi 1 name pubsub subs > subs1 && ipfsi 2 name pubsub subs > subs2 && - test_cmp expected subs1 && - test_cmp expected subs2 + ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh && + ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh && + test_cmp expected_base36 subs1 && + test_cmp expected_base36 subs2 && + test_cmp expected_b58mh subs1_b58mh && + test_cmp expected_b58mh subs2_b58mh ' test_expect_success 'add an object on publisher node' ' @@ -56,15 +62,15 @@ test_expect_success 'wait for the flood' ' test_expect_success 'resolve name in subscriber nodes' ' echo "/ipfs/$HASH_FILE" > expected && - ipfsi 1 name resolve /ipns/$PEERID_0 > name1 && - ipfsi 2 name resolve /ipns/$PEERID_0 > name2 && + ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 && + ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 && test_cmp expected name1 && test_cmp expected name2 ' test_expect_success 'cancel subscriptions to the publisher topic' ' - ipfsi 1 name pubsub cancel /ipns/$PEERID_0 && - ipfsi 2 name pubsub cancel /ipns/$PEERID_0 + ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 && + ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36 ' test_expect_success 'check subscriptions' ' From 4975d9b1793b75bd1903e0e8e7a617e79ada2bfa Mon Sep 17 00:00:00 2001 From: Petar Maymounkov Date: Tue, 18 Aug 2020 08:39:47 -0700 Subject: [PATCH 9/9] renames --- .../keybase.go => keyencode/keyencode.go} | 4 ++-- core/commands/keystore.go | 22 +++++++++---------- core/commands/name/ipnsps.go | 6 ++--- core/commands/name/publish.go | 6 ++--- 4 files changed, 19 insertions(+), 19 deletions(-) rename core/commands/{keybase/keybase.go => keyencode/keyencode.go} (91%) diff --git a/core/commands/keybase/keybase.go b/core/commands/keyencode/keyencode.go similarity index 91% rename from core/commands/keybase/keybase.go rename to core/commands/keyencode/keyencode.go index dbc1413e888..015a6844eff 100644 --- a/core/commands/keybase/keybase.go +++ b/core/commands/keyencode/keyencode.go @@ -1,11 +1,11 @@ -package keybase +package keyencode import ( peer "github.com/libp2p/go-libp2p-core/peer" mbase "github.com/multiformats/go-multibase" ) -const KeyFormatOptionName = "ipns-base" +const IPNSKeyFormatOptionName = "ipns-base" type KeyEncoder struct { baseEnc *mbase.Encoder diff --git a/core/commands/keystore.go b/core/commands/keystore.go index 7aefcd37674..139d8ec7122 100644 --- a/core/commands/keystore.go +++ b/core/commands/keystore.go @@ -15,7 +15,7 @@ import ( oldcmds "github.com/ipfs/go-ipfs/commands" cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" "github.com/ipfs/go-ipfs/core/commands/e" - kb "github.com/ipfs/go-ipfs/core/commands/keybase" + ke "github.com/ipfs/go-ipfs/core/commands/keyencode" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" options "github.com/ipfs/interface-go-ipfs-core/options" "github.com/libp2p/go-libp2p-core/crypto" @@ -81,7 +81,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(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name of key to create"), @@ -108,7 +108,7 @@ var keyGenCmd = &cmds.Command{ if sizefound { opts = append(opts, options.Key.Size(size)) } - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } @@ -223,7 +223,7 @@ var keyImportCmd = &cmds.Command{ Tagline: "Import a key and prints imported key id", }, Options: []cmds.Option{ - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Arguments: []cmds.Argument{ cmds.StringArg("name", true, false, "name to associate with key in keychain"), @@ -236,7 +236,7 @@ var keyImportCmd = &cmds.Command{ return fmt.Errorf("cannot import key with name 'self'") } - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } @@ -303,10 +303,10 @@ var keyListCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } @@ -352,14 +352,14 @@ var keyRenameCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption(keyStoreForceOptionName, "f", "Allow to overwrite an existing key."), - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } @@ -402,14 +402,14 @@ var keyRmCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.BoolOption("l", "Show extra information about keys."), - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } diff --git a/core/commands/name/ipnsps.go b/core/commands/name/ipnsps.go index ceb742aadd6..07e050bf65d 100644 --- a/core/commands/name/ipnsps.go +++ b/core/commands/name/ipnsps.go @@ -7,7 +7,7 @@ import ( cmds "github.com/ipfs/go-ipfs-cmds" "github.com/ipfs/go-ipfs/core/commands/cmdenv" - kb "github.com/ipfs/go-ipfs/core/commands/keybase" + ke "github.com/ipfs/go-ipfs/core/commands/keyencode" "github.com/libp2p/go-libp2p-core/peer" record "github.com/libp2p/go-libp2p-record" ) @@ -74,10 +74,10 @@ var ipnspsSubsCmd = &cmds.Command{ Tagline: "Show current name subscriptions", }, Options: []cmds.Option{ - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err } diff --git a/core/commands/name/publish.go b/core/commands/name/publish.go index 096eb8a9c1b..3e1edf82c30 100644 --- a/core/commands/name/publish.go +++ b/core/commands/name/publish.go @@ -9,7 +9,7 @@ import ( cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" cmds "github.com/ipfs/go-ipfs-cmds" - kb "github.com/ipfs/go-ipfs/core/commands/keybase" + ke "github.com/ipfs/go-ipfs/core/commands/keyencode" iface "github.com/ipfs/interface-go-ipfs-core" options "github.com/ipfs/interface-go-ipfs-core/options" path "github.com/ipfs/interface-go-ipfs-core/path" @@ -83,14 +83,14 @@ Alternatively, publish an using a valid PeerID (as listed by cmds.StringOption(ttlOptionName, "Time duration this record should be cached for. Uses the same syntax as the lifetime option. (caution: experimental)"), cmds.StringOption(keyOptionName, "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'.").WithDefault("self"), cmds.BoolOption(quieterOptionName, "Q", "Write only final hash."), - cmds.StringOption(kb.KeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), + cmds.StringOption(ke.IPNSKeyFormatOptionName, "", "Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash. Takes {b58mh|base36|k|base32|b...}.").WithDefault("base36"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { api, err := cmdenv.GetApi(env, req) if err != nil { return err } - keyEnc, err := kb.KeyEncoderFromString(req.Options[kb.KeyFormatOptionName].(string)) + keyEnc, err := ke.KeyEncoderFromString(req.Options[ke.IPNSKeyFormatOptionName].(string)) if err != nil { return err }