Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateKeypair() (*SecretKey, *PublicKey, error)
- func MnemonicToEntropy(mnemonic string) ([]byte, error)
- func NewRandomElement() (*r255.Element, error)
- func NewRandomScalar() (*r255.Scalar, error)
- func NewSigningContext(context, msg []byte) *merlin.Transcript
- func ScalarFromBytes(b [32]byte) (*r255.Scalar, error)
- func SeedFromMnemonic(mnemonic string, password string) ([64]byte, error)
- func SetKusamaVRF(k bool)
- func TranscriptWithMalleabilityAddressed(t *merlin.Transcript, pk *PublicKey) *merlin.Transcript
- func VerifyBatch(transcripts []*merlin.Transcript, signatures []*Signature, ...) (bool, error)
- type BatchVerifier
- type DerivableKey
- type ExtendedKey
- func DeriveKeyHard(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func DeriveKeySimple(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func DeriveKeySoft(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func NewExtendedKey(k DerivableKey, cc [ChainCodeLength]byte) *ExtendedKey
- func (ek *ExtendedKey) ChainCode() [ChainCodeLength]byte
- func (ek *ExtendedKey) DeriveKey(t *merlin.Transcript) (*ExtendedKey, error)
- func (ek *ExtendedKey) HardDeriveMiniSecretKey(i []byte) (*ExtendedKey, error)
- func (ek *ExtendedKey) Key() DerivableKey
- func (ek *ExtendedKey) Public() (*PublicKey, error)
- func (ek *ExtendedKey) Secret() (*SecretKey, error)
- type MiniSecretKey
- func (s *MiniSecretKey) Decode(in [32]byte) (err error)
- func (mk *MiniSecretKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func (s *MiniSecretKey) Encode() [32]byte
- func (s *MiniSecretKey) ExpandEd25519() *SecretKey
- func (s *MiniSecretKey) ExpandUniform() *SecretKey
- func (mk *MiniSecretKey) HardDeriveMiniSecretKey(i []byte, cc [ChainCodeLength]byte) (*MiniSecretKey, [ChainCodeLength]byte, error)
- func (s *MiniSecretKey) Public() *PublicKey
- type PublicKey
- func (p *PublicKey) Compress() [32]byte
- func (p *PublicKey) Decode(in [32]byte) error
- func (pk *PublicKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func (pk *PublicKey) DeriveScalarAndChaincode(t *merlin.Transcript, cc [ChainCodeLength]byte) (*r255.Scalar, [ChainCodeLength]byte)
- func (p *PublicKey) Encode() [32]byte
- func (p *PublicKey) Verify(s *Signature, t *merlin.Transcript) bool
- func (pk *PublicKey) VrfVerify(t *merlin.Transcript, out *VrfOutput, proof *VrfProof) (bool, error)
- type SecretKey
- func (s *SecretKey) Decode(in [32]byte) error
- func (sk *SecretKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
- func (s *SecretKey) Encode() [32]byte
- func (sk *SecretKey) HardDeriveMiniSecretKey(i []byte, cc [ChainCodeLength]byte) (*MiniSecretKey, [ChainCodeLength]byte, error)
- func (s *SecretKey) Public() (*PublicKey, error)
- func (sk *SecretKey) Sign(t *merlin.Transcript) (*Signature, error)
- func (sk *SecretKey) VrfSign(t *merlin.Transcript) (*VrfInOut, *VrfProof, error)
- type Signature
- type VrfInOut
- type VrfOutput
- type VrfProof
Constants ¶
const ChainCodeLength = 32
const (
// MiniSecretKeyLength is the len in bytes of the MiniSecret Key
MiniSecretKeyLength = 32
)
Variables ¶
var (
ErrDeriveHardKeyType = errors.New("Failed to derive hard key type, DerivableKey must be a SecretKey")
)
var ErrSignatureNotMarkedSchnorrkel = errors.New("signature is not marked as a schnorrkel signature")
ErrSignatureNotMarkedSchnorrkel is returned when attempting to decode a signature that is not marked as schnorrkel
Functions ¶
func GenerateKeypair ¶
GenerateKeypair generates a new schnorrkel secret key and public key
func MnemonicToEntropy ¶
MnemonicToEntropy takes a mnemonic string and reverses it to the entropy An error is returned if the mnemonic is invalid.
func NewRandomElement ¶
NewRandomElement returns a random ristretto element
func NewRandomScalar ¶
NewRandomScalar returns a random ristretto scalar
func NewSigningContext ¶
func NewSigningContext(context, msg []byte) *merlin.Transcript
NewSigningContext returns a new transcript initialized with the context for the signature .see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/context.rs#L183
func ScalarFromBytes ¶
ScalarFromBytes returns a ristretto scalar from the input bytes performs input mod l where l is the group order
func SeedFromMnemonic ¶
SeedFromMnemonic returns a 64-byte seed from a bip39 mnemonic
func SetKusamaVRF ¶
func SetKusamaVRF(k bool)
SetKusama sets the VRF kusama option. Defaults to true.
func TranscriptWithMalleabilityAddressed ¶
func TranscriptWithMalleabilityAddressed(t *merlin.Transcript, pk *PublicKey) *merlin.Transcript
TranscriptWithMalleabilityAddressed returns the input transcript with the public key commited to it, addressing VRF output malleability.
func VerifyBatch ¶
func VerifyBatch(transcripts []*merlin.Transcript, signatures []*Signature, pubkeys []*PublicKey) (bool, error)
VerifyBatch batch verifies the given signatures
Types ¶
type BatchVerifier ¶
type BatchVerifier struct {
// contains filtered or unexported fields
}
func NewBatchVerifier ¶
func NewBatchVerifier() *BatchVerifier
func (*BatchVerifier) Add ¶
func (v *BatchVerifier) Add(t *merlin.Transcript, sig *Signature, pubkey *PublicKey) error
func (*BatchVerifier) Verify ¶
func (v *BatchVerifier) Verify() bool
type DerivableKey ¶
type DerivableKey interface { Encode() [32]byte Decode([32]byte) error DeriveKey(*merlin.Transcript, [ChainCodeLength]byte) (*ExtendedKey, error) }
DerivableKey implements DeriveKey
type ExtendedKey ¶
type ExtendedKey struct {
// contains filtered or unexported fields
}
ExtendedKey consists of a DerivableKey which can be a schnorrkel public or private key as well as chain code
func DeriveKeyHard ¶
func DeriveKeyHard(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
DeriveKeyHard derives a Hard subkey identified by the byte array i and chain code
func DeriveKeySimple ¶
func DeriveKeySimple(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
DeriveKeySimple derives a Soft subkey identified by byte array i and chain code.
func DeriveKeySoft ¶
func DeriveKeySoft(key DerivableKey, i []byte, cc [ChainCodeLength]byte) (*ExtendedKey, error)
DerviveKeySoft is an alias for DervieKeySimple() used to derive a Soft subkey identified by the byte array i and chain code
func NewExtendedKey ¶
func NewExtendedKey(k DerivableKey, cc [ChainCodeLength]byte) *ExtendedKey
NewExtendedKey creates an ExtendedKey given a DerivableKey and chain code
func (*ExtendedKey) ChainCode ¶
func (ek *ExtendedKey) ChainCode() [ChainCodeLength]byte
ChainCode returns the chain code underlying the ExtendedKey
func (*ExtendedKey) DeriveKey ¶
func (ek *ExtendedKey) DeriveKey(t *merlin.Transcript) (*ExtendedKey, error)
DeriveKey derives an extended key from an extended key
func (*ExtendedKey) HardDeriveMiniSecretKey ¶
func (ek *ExtendedKey) HardDeriveMiniSecretKey(i []byte) (*ExtendedKey, error)
HardDeriveMiniSecretKey implements BIP-32 like "hard" derivation of a mini secret from an extended key's secret key
func (*ExtendedKey) Key ¶
func (ek *ExtendedKey) Key() DerivableKey
Key returns the schnorrkel key underlying the ExtendedKey
func (*ExtendedKey) Public ¶
func (ek *ExtendedKey) Public() (*PublicKey, error)
Public returns the PublicKey underlying the ExtendedKey
func (*ExtendedKey) Secret ¶
func (ek *ExtendedKey) Secret() (*SecretKey, error)
Secret returns the SecretKey underlying the ExtendedKey if it's not a secret key, it returns an error
type MiniSecretKey ¶
type MiniSecretKey struct {
// contains filtered or unexported fields
}
MiniSecretKey is a secret scalar
func GenerateMiniSecretKey ¶
func GenerateMiniSecretKey() (*MiniSecretKey, error)
GenerateMiniSecretKey generates a mini secret key from random
func MiniSecretFromMnemonic ¶ added in v1.0.3
func MiniSecretFromMnemonic(mnemonic string, password string) (*MiniSecretKey, error)
MiniSecretFromMnemonic returns a go-schnorrkel MiniSecretKey from a bip39 mnemonic
func NewMiniSecretKey ¶
func NewMiniSecretKey(b [64]byte) *MiniSecretKey
NewMiniSecretKey derives a mini secret key from a byte array
func NewMiniSecretKeyFromRaw ¶
func NewMiniSecretKeyFromRaw(b [32]byte) (*MiniSecretKey, error)
NewMiniSecretKeyFromRaw derives a mini secret key from little-endian encoded raw bytes.
func (*MiniSecretKey) Decode ¶
func (s *MiniSecretKey) Decode(in [32]byte) (err error)
func (*MiniSecretKey) DeriveKey ¶
func (mk *MiniSecretKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
DeriveKey derives an Extended Key from the Mini Secret Key
func (*MiniSecretKey) Encode ¶
func (s *MiniSecretKey) Encode() [32]byte
func (*MiniSecretKey) ExpandEd25519 ¶
func (s *MiniSecretKey) ExpandEd25519() *SecretKey
ExpandEd25519 expands a mini secret key into a secret key https://github.com/w3f/schnorrkel/blob/43f7fc00724edd1ef53d5ae13d82d240ed6202d5/src/keys.rs#L196
func (*MiniSecretKey) ExpandUniform ¶
func (s *MiniSecretKey) ExpandUniform() *SecretKey
ExpandUniform
func (*MiniSecretKey) HardDeriveMiniSecretKey ¶
func (mk *MiniSecretKey) HardDeriveMiniSecretKey(i []byte, cc [ChainCodeLength]byte) ( *MiniSecretKey, [ChainCodeLength]byte, error)
HardDeriveMiniSecretKey implements BIP-32 like "hard" derivation of a mini secret from a mini secret key
func (*MiniSecretKey) Public ¶
func (s *MiniSecretKey) Public() *PublicKey
Public gets the public key corresponding to this mini secret key
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey is a field element
func NewPublicKey ¶
NewPublicKey creates a new public key from input bytes
func (*PublicKey) Compress ¶ added in v1.0.3
Compress returns the encoding of the point underlying the public key
func (*PublicKey) DeriveKey ¶
func (pk *PublicKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
func (*PublicKey) DeriveScalarAndChaincode ¶
func (pk *PublicKey) DeriveScalarAndChaincode(t *merlin.Transcript, cc [ChainCodeLength]byte) (*r255.Scalar, [ChainCodeLength]byte)
DeriveScalarAndChaincode derives a new scalar and chain code from an existing public key and chain code
type SecretKey ¶
type SecretKey struct {
// contains filtered or unexported fields
}
SecretKey consists of a secret scalar and a signing nonce
func NewSecretKey ¶
NewSecretKey creates a new secret key from input bytes
func (*SecretKey) DeriveKey ¶
func (sk *SecretKey) DeriveKey(t *merlin.Transcript, cc [ChainCodeLength]byte) (*ExtendedKey, error)
DeriveKey derives a new secret key and chain code from an existing secret key and chain code
func (*SecretKey) HardDeriveMiniSecretKey ¶
func (sk *SecretKey) HardDeriveMiniSecretKey(i []byte, cc [ChainCodeLength]byte) ( *MiniSecretKey, [ChainCodeLength]byte, error)
HardDeriveMiniSecretKey implements BIP-32 like "hard" derivation of a mini secret from a secret key
func (*SecretKey) Sign ¶
func (sk *SecretKey) Sign(t *merlin.Transcript) (*Signature, error)
Sign uses the schnorr signature algorithm to sign a message See the following for the transcript message https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L158 Schnorr w/ transcript, secret key x: 1. choose random r from group 2. R = gr 3. k = scalar(transcript.extract_bytes()) 4. s = kx + r signature: (R, s) public key used for verification: y = g^x
type Signature ¶
Signature holds a schnorrkel signature
func (*Signature) Decode ¶
Decode sets a Signature from bytes see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L100
func (*Signature) DecodeNotDistinguishedFromEd25519 ¶
DecodeNotDistinguishedFromEd25519 sets a signature from bytes, not checking if the signature is explicitly marked as a schnorrkel signature
func (*Signature) Encode ¶
Encode turns a signature into a byte array see: https://github.com/w3f/schnorrkel/blob/db61369a6e77f8074eb3247f9040ccde55697f20/src/sign.rs#L77
type VrfInOut ¶
type VrfInOut struct {
// contains filtered or unexported fields
}
func (*VrfInOut) Encode ¶
EncodeOutput returns the 64-byte encoding of the input and output concatenated
func (*VrfInOut) MakeBytes ¶
MakeBytes returns raw bytes output from the VRF It returns a byte slice of the given size see https://github.com/w3f/schnorrkel/blob/master/src/vrf.rs#L334
type VrfOutput ¶
type VrfOutput struct {
// contains filtered or unexported fields
}
func (*VrfOutput) AttachInput ¶
func (out *VrfOutput) AttachInput(pub *PublicKey, t *merlin.Transcript) *VrfInOut
AttachInput returns a VrfInOut pair from an output https://github.com/w3f/schnorrkel/blob/master/src/vrf.rs#L249