key

package
v1.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const ENCRYPTION_ROUNDS = 1048576

Variables

This section is empty.

Functions

func CreateED25519KeyFromSeed

func CreateED25519KeyFromSeed(privateBytes []byte) ([]byte, []byte, error)

func CreateP384Key

func CreateP384Key(privateBytes []byte) (*ecdsa.PrivateKey, []byte, []byte, string, string)

func CreateSECP256K1Key

func CreateSECP256K1Key(privateBytes []byte) (*ecdsa.PrivateKey, []byte, []byte, string, string)

func Decrypt

func Decrypt(priv *ecdsa.PrivateKey, encryptedObject string) ([]byte, error)

func EllipticParamsToJWK

func EllipticParamsToJWK(crv string, kty string, x []byte, y []byte) (*jwk.JWK, error)

func EllipticPubkeyToJWK

func EllipticPubkeyToJWK(pub *ecdsa.PublicKey) (*jwk.JWK, error)

func EncryptToEllipticPubkey

func EncryptToEllipticPubkey(pub *ecdsa.PublicKey, msg []byte) (string, error)

func JWKToElliptic

func JWKToElliptic(jsonWebKey *jwk.JWK) (*ecdsa.PublicKey, error)

func SignED25519

func SignED25519(priv *ed25519.PrivateKey, keyId string, header string, msg []byte) (string, error)

func SignElliptic

func SignElliptic(priv *ecdsa.PrivateKey, keyId string, header string, msg []byte) (string, error)

func VerifyED25519

func VerifyED25519(pub *ed25519.PublicKey, signature string) ([]byte, error)

func VerifyElliptic

func VerifyElliptic(pub *ecdsa.PublicKey, signature string) ([]byte, string, error)

Types

type Config

type Config struct {
	Db state.DBManager
}

type EllipticJwk

type EllipticJwk struct {
	Crv string `json:"crv"`
	Kty string `json:"kty"`
	X   string `json:"x"`
	Y   string `json:"y"`
}

type KeyManager

type KeyManager interface {
	// InitSeed creates the master key encrypted with a passphrase, returns the mnemonic
	InitSeed(seedImport string, passphrase string) (string, error)

	// UnlockSeed unlocks the master key with passphrase
	UnlockSeed(passphrase string) error

	// GetSeed gets the seed phrase mnemonic that was used to initialize this daemon
	GetSeed() (string, error)

	IsLocked() bool

	// New Child will create a new child key from the master key.
	// If current index is specified, that will be used. Otherwise generated.
	// Master seed should be unlocked first. Child ID should be tracked
	// by the caller. Private key bytes are also returned.
	NewChild(parentId int64, keyIndex uint32) (int64, []byte, uint32, error)

	// GetChildKey gets the private key bytes for a certain child derrivation.
	GetChildKey(childId int64) ([]byte, error)

	GetIndex(id int64) (uint32, error)

	// GetChildrenKeys gets all the children private keys created from parent
	GetChildrenKeys(parentId int64) ([][]byte, []uint32, error)

	// CreateNewED25519Key will create a new ED25519 keypair and save to DB under the identity key passed in.
	// Returns public key, private key, the backing store ID, and the backing key index.
	CreateNewED25519Key(int64) ([]byte, []byte, int64, uint32, error)

	// CreateNewSECP256K1Key will create a new SECP256K1 keypair and save to DB under the identity key passed in.
	// Returns private key, the backing store ID, and the backing key index.
	CreateNewSECP256K1Key(int64) (*ecdsa.PrivateKey, int64, uint32, error)

	// CreateNewP384Key will create a new P384 keypair and save to DB under the identity key passed in.
	// Returns private key, the backing store ID, and the backing key index.
	CreateNewP384Key(int64) (*ecdsa.PrivateKey, int64, uint32, error)

	// Decrypt will attempt to decrypt a message with one of the saved keys
	// Returns the decrypted message as bytes.
	Decrypt(protected, ciphertext, iv, tag string) ([]byte, error)
}

func New

func New(cfg Config) (KeyManager, error)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL