Documentation ¶
Overview ¶
Package chainkd This is an extension to ed25519.Sign that is compatible with NaCl `crypto_sign` function taking 64-byte expanded private key (where the left part is a pre-multiplied scalar and the right part is "prefix" used for generating a nonce).
Invariants: 1) Expanded(PrivateKey).Sign() == PrivateKey.Sign() 2) InnerSign(Expanded(PrivateKey)) == Sign(PrivateKey)
Index ¶
- Constants
- Variables
- func Ed25519InnerSign(privateKey ExpandedPrivateKey, message []byte) []byte
- func NewXKeys(r io.Reader) (xprv XPrv, xpub XPub, err error)
- func XPubKeys(xpubs []XPub) []ed25519.PublicKey
- type ExpandedPrivateKey
- type XPrv
- func (xprv XPrv) Bytes() []byte
- func (xprv XPrv) Child(sel []byte, hardened bool) XPrv
- func (xprv XPrv) Derive(path [][]byte) XPrv
- func (xprv XPrv) ExpandedPrivateKey() ExpandedPrivateKey
- func (xprv XPrv) MarshalText() ([]byte, error)
- func (xprv XPrv) Sign(msg []byte) []byte
- func (xprv XPrv) String() string
- func (xprv *XPrv) UnmarshalText(inp []byte) error
- func (xprv XPrv) XPub() (xpub XPub)
- type XPub
- func (xpub XPub) Bytes() []byte
- func (xpub XPub) Child(sel []byte) (res XPub)
- func (xpub XPub) Derive(path [][]byte) XPub
- func (xpub XPub) MarshalText() ([]byte, error)
- func (xpub XPub) PublicKey() ed25519.PublicKey
- func (xpub XPub) String() string
- func (xpub *XPub) UnmarshalText(inp []byte) error
- func (xpub XPub) Verify(msg []byte, sig []byte) bool
Constants ¶
const (
// ExpandedPrivateKeySize is the size, in bytes, of a "secret key" as defined in NaCl.
ExpandedPrivateKeySize = 64
)
Variables ¶
var ( ErrBadKeyLen = errors.New("bad key length") ErrBadKeyStr = errors.New("bad key string") )
Functions ¶
func Ed25519InnerSign ¶
func Ed25519InnerSign(privateKey ExpandedPrivateKey, message []byte) []byte
Ed25519InnerSign signs the message with expanded private key and returns a signature. It will panic if len(privateKey) is not ExpandedPrivateKeySize.
Types ¶
type ExpandedPrivateKey ¶
type ExpandedPrivateKey []byte
ExpandedPrivateKey is the type of NaCl secret keys. It implements crypto.Signer.
func (ExpandedPrivateKey) Public ¶
func (priv ExpandedPrivateKey) Public() crypto.PublicKey
Public returns the PublicKey corresponding to secret key.
func (ExpandedPrivateKey) Sign ¶
func (priv ExpandedPrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error)
Sign signs the given message with expanded private key. Ed25519 performs two passes over messages to be signed and therefore cannot handle pre-hashed messages. Thus opts.HashFunc() must return zero to indicate the message hasn't been hashed. This can be achieved by passing crypto.Hash(0) as the value for opts.
type XPrv ¶
type XPrv [64]byte
XPrv external private key
func NewXPrv ¶
NewXPrv takes a source of random bytes and produces a new XPrv. If r is nil, crypto/rand.Reader is used.
func (XPrv) Child ¶
Child derives a child xprv based on `selector` string and `hardened` flag. If `hardened` is false, child xpub can be derived independently from the parent xpub without using the parent xprv. If `hardened` is true, child key can only be derived from the parent xprv.
func (XPrv) Derive ¶
Derive generates a child xprv by recursively deriving non-hardened child xprvs over the list of selectors: `Derive([a,b,c,...]) == Child(a).Child(b).Child(c)...`
func (XPrv) ExpandedPrivateKey ¶
func (xprv XPrv) ExpandedPrivateKey() ExpandedPrivateKey
ExpandedPrivateKey generates a 64-byte key where the first half is the scalar copied from xprv, and the second half is the `prefix` is generated via PRF from the xprv.
func (XPrv) MarshalText ¶
func (XPrv) Sign ¶
Sign creates an EdDSA signature using expanded private key derived from the xprv.
func (*XPrv) UnmarshalText ¶
type XPub ¶
type XPub [64]byte
XPub external public key
func DeriveXPubs ¶
func (XPub) Child ¶
Child derives a child xpub based on `selector` string. The corresponding child xprv can be derived from the parent xprv using non-hardened derivation: `parentxprv.Child(sel, false)`.
func (XPub) Derive ¶
Derive generates a child xpub by recursively deriving non-hardened child xpubs over the list of selectors: `Derive([a,b,c,...]) == Child(a).Child(b).Child(c)...`