Commit 23a26c05 authored by Petar Maymounkov's avatar Petar Maymounkov

rename -f to --ipns-base

parent 80e859ef
...@@ -68,11 +68,11 @@ type KeyRenameOutput struct { ...@@ -68,11 +68,11 @@ type KeyRenameOutput struct {
} }
const ( const (
keyStoreAlgorithmDefault = options.RSAKey keyStoreAlgorithmDefault = options.RSAKey
keyStoreTypeOptionName = "type" keyStoreTypeOptionName = "type"
keyStoreSizeOptionName = "size" keyStoreSizeOptionName = "size"
keyFormatOptionName = "format" keyFormatOptionName = "ipns-base"
oldKeyOptionName = "oldkey" oldKeyOptionName = "oldkey"
) )
var keyGenCmd = &cmds.Command{ var keyGenCmd = &cmds.Command{
...@@ -82,7 +82,7 @@ var keyGenCmd = &cmds.Command{ ...@@ -82,7 +82,7 @@ var keyGenCmd = &cmds.Command{
Options: []cmds.Option{ Options: []cmds.Option{
cmds.StringOption(keyStoreTypeOptionName, "t", "type of the key to create: rsa, ed25519").WithDefault(keyStoreAlgorithmDefault), 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.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{ Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "name of key to create"), cmds.StringArg("name", true, false, "name of key to create"),
...@@ -223,7 +223,7 @@ var keyImportCmd = &cmds.Command{ ...@@ -223,7 +223,7 @@ var keyImportCmd = &cmds.Command{
Tagline: "Import a key and prints imported key id", Tagline: "Import a key and prints imported key id",
}, },
Options: []cmds.Option{ 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{ Arguments: []cmds.Argument{
cmds.StringArg("name", true, false, "name to associate with key in keychain"), cmds.StringArg("name", true, false, "name to associate with key in keychain"),
...@@ -298,7 +298,7 @@ var keyListCmd = &cmds.Command{ ...@@ -298,7 +298,7 @@ var keyListCmd = &cmds.Command{
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.BoolOption("l", "Show extra information about keys."), 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 { Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil { if err := verifyIDFormatLabel(req.Options[keyFormatOptionName].(string)); err != nil {
...@@ -395,7 +395,7 @@ var keyRmCmd = &cmds.Command{ ...@@ -395,7 +395,7 @@ var keyRmCmd = &cmds.Command{
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.BoolOption("l", "Show extra information about keys."), 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 { Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
api, err := cmdenv.GetApi(env, req) api, err := cmdenv.GetApi(env, req)
...@@ -417,7 +417,7 @@ var keyRmCmd = &cmds.Command{ ...@@ -417,7 +417,7 @@ var keyRmCmd = &cmds.Command{
list = append(list, KeyOutput{ list = append(list, KeyOutput{
Name: name, Name: name,
Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)), // key.ID().Pretty(), Id: formatID(key.ID(), req.Options[keyFormatOptionName].(string)),
}) })
} }
......
...@@ -56,8 +56,8 @@ test_rotate() { ...@@ -56,8 +56,8 @@ test_rotate() {
test_expect_success "checking ID" ' test_expect_success "checking ID" '
ipfs config Identity.PeerID > expected-id && ipfs config Identity.PeerID > expected-id &&
ipfs id -f "<id>\n" > actual-id && ipfs id -f "<id>\n" > actual-id &&
ipfs key list -l -f=b58mh | grep self | cut -d " " -f1 > keystore-id && ipfs key list -l --ipns-base=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 oldkey | cut -d " " -f1 | tr -d "\n" > old-keystore-id &&
test_cmp expected-id actual-id && test_cmp expected-id actual-id &&
test_cmp expected-id keystore-id && test_cmp expected-id keystore-id &&
test_cmp old-keystore-id first_id test_cmp old-keystore-id first_id
......
...@@ -24,7 +24,7 @@ test_name_with_self() { ...@@ -24,7 +24,7 @@ test_name_with_self() {
ipfs init --profile=test -a=ed25519 > /dev/null ipfs init --profile=test -a=ed25519 > /dev/null
;; ;;
esac && 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}" test_check_peerid "${PEERID}"
' '
...@@ -109,8 +109,8 @@ test_name_with_self() { ...@@ -109,8 +109,8 @@ test_name_with_self() {
# test publishing with B36CID and B58MH resolve to the same B36CID # test publishing with B36CID and B58MH resolve to the same B36CID
test_expect_success "verify self key output" ' test_expect_success "verify self key output" '
B58MH_ID=`ipfs key list -f=b58mh -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 -f=b36cid -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 "${B58MH_ID}" &&
test_check_peerid "${B36CID_ID}" test_check_peerid "${B36CID_ID}"
' '
...@@ -250,15 +250,15 @@ test_name_with_key() { ...@@ -250,15 +250,15 @@ test_name_with_key() {
test_expect_success "'prepare keys" ' test_expect_success "'prepare keys" '
case $GEN_ALG in case $GEN_ALG in
rsa) rsa)
export KEY=`ipfs key gen -f=b58mh --type=rsa --size=2048 key` && export KEY=`ipfs key gen --ipns-base=b58mh --type=rsa --size=2048 key` &&
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1` export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1`
;; ;;
ed25519_b58) ed25519_b58)
export KEY=`ipfs key gen -f=b58mh --type=ed25519 key` export KEY=`ipfs key gen --ipns-base=b58mh --type=ed25519 key`
export KEY_B36CID=`ipfs key list -f=b36cid -l | grep key | cut -d " " -f1` export KEY_B36CID=`ipfs key list --ipns-base=b36cid -l | grep key | cut -d " " -f1`
;; ;;
ed25519_b36) 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 export KEY_B36CID=$KEY
;; ;;
esac && esac &&
......
...@@ -113,7 +113,7 @@ test_expect_success "Add the test directory" ' ...@@ -113,7 +113,7 @@ test_expect_success "Add the test directory" '
' '
test_expect_success "Publish test text file to IPNS using RSA keys" ' 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_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=$(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) 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" ' ...@@ -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" ' 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_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) ED25519_IPNS_IDv1_DAGPB=$(echo "$ED25519_IPNS_IDv1" | ipfs cid format -v 1 -b base36 --codec protobuf)
test_check_peerid "${ED25519_KEY}" && test_check_peerid "${ED25519_KEY}" &&
ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out && ipfs name publish --key test_key_ed25519 --allow-offline -Q "/ipfs/$CIDv1" > name_publish_out &&
......
...@@ -22,8 +22,8 @@ test_expect_success "resolve: prepare dag" ' ...@@ -22,8 +22,8 @@ test_expect_success "resolve: prepare dag" '
' '
test_expect_success "resolve: prepare keys" ' test_expect_success "resolve: prepare keys" '
self_hash=$(ipfs key list -f=b36cid -l | grep self | cut -d " " -f1) && self_hash=$(ipfs key list --ipns-base=b36cid -l | grep self | cut -d " " -f1) &&
alt_hash=$(ipfs key gen -f=b36cid -t rsa alt) alt_hash=$(ipfs key gen --ipns-base=b36cid -t rsa alt)
echo self_hash $self_hash echo self_hash $self_hash
echo $(ipfs id -f="<id>") echo $(ipfs id -f="<id>")
' '
......
...@@ -13,10 +13,10 @@ test_init_ipfs ...@@ -13,10 +13,10 @@ test_init_ipfs
test_key_cmd() { test_key_cmd() {
# test key output format # test key output format
test_expect_success "create an RSA key and test B58MH/B36CID output formats" ' 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 && test_check_rsa2048_b58mh_peerid $PEERID &&
ipfs key rm key_rsa && 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 test_check_rsa2048_b36cid_peerid $PEERID
' '
...@@ -27,18 +27,18 @@ rm key_rsa.key ...@@ -27,18 +27,18 @@ rm key_rsa.key
' '
test_expect_success "test RSA key B58MH/B36CID multihash format" ' 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 && 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 && test_check_rsa2048_b36cid_peerid $PEERID &&
ipfs key rm key_rsa ipfs key rm key_rsa
' '
test_expect_success "create an ED25519 key and test B58MH/B36CID output formats" ' 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 && test_check_ed25519_b58mh_peerid $PEERID &&
ipfs key rm key_ed25519 && 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 test_check_ed25519_b36cid_peerid $PEERID
' '
...@@ -49,9 +49,9 @@ rm key_ed25519.key ...@@ -49,9 +49,9 @@ rm key_ed25519.key
' '
test_expect_success "test ED25519 key B58MH/B36CID multihash format" ' 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 && 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 && test_check_ed25519_b36cid_peerid $PEERID &&
ipfs key rm key_ed25519 ipfs key rm key_ed25519
' '
...@@ -59,12 +59,12 @@ ipfs key rm key_ed25519 ...@@ -59,12 +59,12 @@ ipfs key rm key_ed25519
test_expect_success "create a new rsa key" ' 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 echo $rsahash > rsa_key_id
' '
test_expect_success "create a new ed25519 key" ' 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 echo $edhash > ed25519_key_id
' '
...@@ -119,13 +119,13 @@ ipfs key rm key_ed25519 ...@@ -119,13 +119,13 @@ ipfs key rm key_ed25519
' '
test_expect_success "key hashes show up in long list output" ' 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 --ipns-base=b58mh | grep $edhash > /dev/null &&
ipfs key list -l -f=b58mh | grep $rsahash > /dev/null ipfs key list -l --ipns-base=b58mh | grep $rsahash > /dev/null
' '
test_expect_success "key list -l contains self key with peerID" ' test_expect_success "key list -l contains self key with peerID" '
PeerID="$(ipfs config Identity.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" ' test_expect_success "key rm remove a key" '
......
...@@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" ' ...@@ -62,7 +62,7 @@ test_expect_success "ipfs daemon --offline --mount fails - #2995" '
test_launch_ipfs_daemon --offline test_launch_ipfs_daemon --offline
test_expect_success "'ipfs name resolve' succeeds after ipfs id when 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}" && test_check_peerid "${PEERID}" &&
ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out ipfs name publish --allow-offline -Q "/ipfs/$HASH_WELCOME_DOCS" >publish_out
' '
......
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