Documentation
¶
Overview ¶
Package srkeyring provides functions to implementation HDKD (Hierarchical Deterministic Key Derivation) using sr25519 (Schnorr over Ristretto25519).
Compatible with Substrates key generation and command line utility subkey.
Supports SS58 address formatting and SecretURI key derivation format specified as; `<mnemonic, mini-secret, or SS58 address>[//hard-derivation][/soft-derivation][///password]`.
Index ¶
- Constants
- Variables
- func DecodeHex(str string, prefix HexPrefix) (seed []byte, ok bool)
- func DecodeSS58Address(addr string, net Network, ctype ChecksumType) ([32]byte, error)
- func EncodeHex(raw []byte, prefix HexPrefix) string
- func SS58Address(addr [32]byte, net Network, ctype ChecksumType) (string, error)
- type ChecksumType
- type DerivablePrivateKey
- type HexPrefix
- type KeyRing
- func (k *KeyRing) Mnemonic() (string, error)
- func (k *KeyRing) Public() [32]byte
- func (k *KeyRing) PublicHex() string
- func (k *KeyRing) SS58Address() (string, error)
- func (k *KeyRing) Secret() [32]byte
- func (k *KeyRing) SecretHex() string
- func (k *KeyRing) Seed() ([32]byte, error)
- func (k *KeyRing) SeedHex() (string, error)
- func (k *KeyRing) Sign(t *merlin.Transcript) (signature [64]byte, err error)
- func (k *KeyRing) SigningContext(msg []byte) *merlin.Transcript
- func (k *KeyRing) Verify(t *merlin.Transcript, signature [64]byte) bool
- func (k *KeyRing) VrfSign(t *merlin.Transcript) (output [32]byte, proof [64]byte, err error)
- func (k *KeyRing) VrfVerify(t *merlin.Transcript, output [32]byte, proof [64]byte) (bool, error)
- type NetSubstrate
- type Network
- type PhraseType
- type SecretURI
- type WordCount
Constants ¶
const ( // MiniSecretKeyLength is the length of the MiniSecret Key MiniSecretKeyLength = 32 // SecretKeyLength is the length of the SecretKey SecretKeyLength = 64 )
Variables ¶
var ( ErrDecodingSecretHex = errors.New("Error decoding secret hex phrase") ErrUnknownPhraseType = errors.New("SURI phrase type is unknown or not set") ErrSeedNotAvailable = errors.New("Unable to get seed from public address data") ErrInvalidWordCount = errors.New("An invalid WordCount was given, valid values are 12, 15, 18, 21, or 24") ErrNonMnemonic = errors.New("Error KeyRing was generated from non mnemonic source") )
Functions ¶
func DecodeSS58Address ¶
func DecodeSS58Address(addr string, net Network, ctype ChecksumType) ([32]byte, error)
DecodeSS58Address takes a string and checks if it is a validly encoded SS58 address and returns the raw address in bytes
func EncodeHex ¶
EncodeHex encodes the raw bytes into a hex encoded string and appends any prefix required
func SS58Address ¶
func SS58Address(addr [32]byte, net Network, ctype ChecksumType) (string, error)
SS58Address derives ss58 address from the address, network, and checksumType
Types ¶
type ChecksumType ¶
type ChecksumType int
ChecksumType represents the one or more checksum types. More here: https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)#checksum-types
const ( // SS58Checksum uses the concat(address-type, address) as blake2b hash pre-image SS58Checksum ChecksumType = iota // AccountID uses the address as the blake2b hash pre-image AccountID )
type DerivablePrivateKey ¶
type DerivablePrivateKey bool
DerivablePrivateKey indicates if the returned sr25519.DerivableKey is a PublicKey or SecretKey
type KeyRing ¶
type KeyRing struct {
// contains filtered or unexported fields
}
KeyRing defines a key pair from a derive Secret URI
func FromPublic ¶
FromPublic returns a KeyRing from the raw bytes of a public key
func Generate ¶
Generate creates a new KeyRing with a randomly created mnemonic of the specified number of words
func (*KeyRing) Mnemonic ¶
Mnemonic returns the mnemonic phrase if the KeyRing was generated by a mnemonic phrase or an error if generated by other source
func (*KeyRing) SS58Address ¶
SS58Address returns the public key encoded as a SS58 address
func (*KeyRing) Sign ¶
func (k *KeyRing) Sign(t *merlin.Transcript) (signature [64]byte, err error)
Sign signs the message using the secret key
func (*KeyRing) SigningContext ¶
func (k *KeyRing) SigningContext(msg []byte) *merlin.Transcript
SigningContext returns the transcript used for message signing for the Network set
func (*KeyRing) Verify ¶
func (k *KeyRing) Verify(t *merlin.Transcript, signature [64]byte) bool
Verify the message against the signature
type NetSubstrate ¶
type NetSubstrate struct{}
NetSubstrate implements the Network interface to define Substrates mainnet settings
func (NetSubstrate) AddressPrefix ¶
func (n NetSubstrate) AddressPrefix() HexPrefix
AddressPrefix returns a prefix to apply to hex encoded addresses for public key and private seed
func (NetSubstrate) ChecksumEnd ¶
func (n NetSubstrate) ChecksumEnd() int
ChecksumEnd is the end byte position of the blake2d checksum calculated when generating the SS58 address checksum
func (NetSubstrate) ChecksumStart ¶
func (n NetSubstrate) ChecksumStart() int
ChecksumStart is the starting byte position of the blake2d checksum calculated when generating the SS58 address checksum
func (NetSubstrate) Name ¶
func (n NetSubstrate) Name() string
Name returns the network name used in the KeyRing SigningContext transcript
func (NetSubstrate) Version ¶
func (n NetSubstrate) Version() uint8
Version returns the network version number used in SS58 address formatting
type Network ¶
type Network interface {
// Name returns the network name used in the KeyRing SigningContext transcript
Name() string
// Version returns the network version number used in SS58 address formatting
// see https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)#checksum-types
// section Address Type
Version() uint8
// AddressPrefix returns a prefix to apply to hex encoded addresses for
// public key and private seed
AddressPrefix() HexPrefix
// ChecksumStart is the starting byte position of the blake2d checksum
// calculated when generating the SS58 address checksum. Valid ranges
// are 0 to 30. Standard value is 0.
ChecksumStart() int
// ChecksumEnd is the end byte position of the blake2d checksum
// calculated when generating the SS58 address checksum. Valid ranges
// are 2 to 32, where ChecksumEnd must be a higher number than
// ChecksumStart. Standard value is 2.
ChecksumEnd() int
}
Network defines the interface for a specific networks settings to be used for key generation and address formatting
type PhraseType ¶
type PhraseType int
PhraseType specifies the type of data that was passed as the phrase component in a Secret URI
const ( SecretHex PhraseType = iota + 1 SS58Public Mnemonic RawPublicKey )
type SecretURI ¶
type SecretURI struct {
Phrase string
Path string
Password string
Network Network
Type PhraseType
}
SecretURI defines a struct consisting of the parts of a Secret URI
func NewSecretURI ¶
NewSecretURI takes a given string Secret URI and splits it into Phrase, Path, and Password components given the format <phrase><path>///<password> and returns it as a struct
func (*SecretURI) DerivableKey ¶
func (s *SecretURI) DerivableKey() (sr25519.DerivableKey, DerivablePrivateKey, error)
DerivableKey returns a DerivableKey from the Secret URI
func (*SecretURI) GetJunctions ¶
GetJunctions returns the junction parts of the path component of the Secret URI.