Documentation
¶
Overview ¶
Package keystore manages the private keys OrbitDB identities sign with.
It mirrors src/key-store.js in @orbitdb/core: keys are secp256k1 keys from go-libp2p's crypto package, stored as their 32 raw bytes under "private_<id>", public keys are exchanged as the hex of their 33-byte compressed form, and signatures are the hex of a DER-encoded ECDSA signature over SHA-256 of the message. Signing is deterministic (RFC 6979), so Go and JavaScript produce byte-identical signatures for the same key and message.
Index ¶
- Constants
- Variables
- func PublicKey(key crypto.PrivKey) (string, error)
- func SignMessage(key crypto.PrivKey, data []byte) (string, error)
- func UnmarshalPrivateKey(raw []byte) (crypto.PrivKey, error)
- func UnmarshalPublicKey(raw []byte) (crypto.PubKey, error)
- func VerifyMessage(signature, publicKey string, data []byte) bool
- type KeyStore
- func (ks *KeyStore) AddKey(ctx context.Context, id string, key crypto.PrivKey) error
- func (ks *KeyStore) Clear(ctx context.Context) error
- func (ks *KeyStore) Close() error
- func (ks *KeyStore) CreateKey(ctx context.Context, id string) (crypto.PrivKey, error)
- func (ks *KeyStore) GetKey(ctx context.Context, id string) (crypto.PrivKey, error)
- func (ks *KeyStore) GetOrCreateKey(ctx context.Context, id string) (crypto.PrivKey, error)
- func (ks *KeyStore) HasKey(ctx context.Context, id string) (bool, error)
- type Options
Constants ¶
const DefaultPath = "./keystore"
DefaultPath is where New keeps keys when neither Storage nor Path is set.
Variables ¶
var ErrNotFound = errors.New("keystore: key not found")
ErrNotFound is returned by GetKey when the keystore has no key for an id.
Functions ¶
func PublicKey ¶
PublicKey returns the hex encoding of key's raw public key, the form identities and entries carry.
func SignMessage ¶
SignMessage signs data with key and returns the hex-encoded signature.
func UnmarshalPrivateKey ¶
UnmarshalPrivateKey parses a raw private key the way @libp2p/crypto's privateKeyFromRaw does: 32 bytes is secp256k1, 64 bytes is Ed25519 and anything else is tried as a PKCS#1 RSA key.
func UnmarshalPublicKey ¶
UnmarshalPublicKey parses a raw public key the way @libp2p/crypto's publicKeyFromRaw does: 32 bytes is Ed25519, 33 bytes is compressed secp256k1 and anything else is tried as a DER (PKIX) ECDSA or RSA key.
func VerifyMessage ¶
VerifyMessage reports whether signature (hex) is a valid signature of data by publicKey (hex of the raw public key). Malformed input verifies as false.
Types ¶
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore stores private keys by id.
func (*KeyStore) CreateKey ¶
CreateKey generates a secp256k1 key and stores it under id. Like @orbitdb/core it replaces any key already stored for id; callers that want get-or-create should call GetKey first.
func (*KeyStore) GetOrCreateKey ¶
GetOrCreateKey returns the key stored for id, creating one if there is none.