-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7582 from ipfs/petar/keys
use b36 keys by default for keys and IPNS
- Loading branch information
Showing
15 changed files
with
197 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package keyencode | ||
|
||
import ( | ||
peer "github.com/libp2p/go-libp2p-core/peer" | ||
mbase "github.com/multiformats/go-multibase" | ||
) | ||
|
||
const IPNSKeyFormatOptionName = "ipns-base" | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.