crypto

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package crypto implements the cryptography used in the Cashu protocol as explained in Cashu.

Index

Constants

View Source
const DomainSeparator = "Secp256k1_HashToCurve_Cashu_"
View Source
const MAX_ORDER = 60

Variables

This section is empty.

Functions

func BlindMessage

func BlindMessage(secret string, r *secp256k1.PrivateKey) (*secp256k1.PublicKey,
	*secp256k1.PrivateKey, error)

B_ = Y + rG

func DeriveKeysetId

func DeriveKeysetId(keyset map[uint64]*secp256k1.PublicKey) string

DeriveKeysetId returns the string ID derived from the map keyset The steps to derive the ID are: - sort public keys by their amount in ascending order - concatenate all public keys to one byte array - HASH_SHA256 the concatenated public keys - take the first 14 characters of the hex-encoded hash - prefix it with a keyset ID version byte

func DeriveKeysetPath added in v0.2.0

func DeriveKeysetPath(key *hdkeychain.ExtendedKey, index uint32) (*hdkeychain.ExtendedKey, error)

func GenerateDLEQ added in v0.3.0

func GenerateDLEQ(
	a *secp256k1.PrivateKey,
	B_ *secp256k1.PublicKey,
	C_ *secp256k1.PublicKey,
) (*secp256k1.PrivateKey, *secp256k1.PrivateKey)

func HashE added in v0.3.0

func HashE(publicKeys []*secp256k1.PublicKey) [32]byte

func HashToCurve

func HashToCurve(message []byte) (*secp256k1.PublicKey, error)

The domain separator is b"Secp256k1_HashToCurve_Cashu_" or bytes.fromhex("536563703235366b315f48617368546f43757276655f43617368755f").

func MapPubKeys added in v0.2.0

func MapPubKeys(keys nut01.KeysMap) (map[uint64]*secp256k1.PublicKey, error)

func SignBlindedMessage

func SignBlindedMessage(B_ *secp256k1.PublicKey, k *secp256k1.PrivateKey) *secp256k1.PublicKey

C_ = kB_

func UnblindSignature

func UnblindSignature(C_ *secp256k1.PublicKey, r *secp256k1.PrivateKey,
	K *secp256k1.PublicKey) *secp256k1.PublicKey

C = C_ - rK

func Verify

func Verify(secret string, k *secp256k1.PrivateKey, C *secp256k1.PublicKey) bool

k * HashToCurve(secret) == C

func VerifyDLEQ added in v0.3.0

func VerifyDLEQ(
	e *secp256k1.PrivateKey,
	s *secp256k1.PrivateKey,
	A *secp256k1.PublicKey,
	B_ *secp256k1.PublicKey,
	C_ *secp256k1.PublicKey,
) bool

Types

type KeyPair

type KeyPair struct {
	PrivateKey *secp256k1.PrivateKey
	PublicKey  *secp256k1.PublicKey
}

func (*KeyPair) MarshalJSON

func (kp *KeyPair) MarshalJSON() ([]byte, error)

func (*KeyPair) UnmarshalJSON

func (kp *KeyPair) UnmarshalJSON(data []byte) error

type KeyPairTemp

type KeyPairTemp struct {
	PrivateKey []byte `json:"private_key"`
	PublicKey  []byte `json:"public_key"`
}

type KeysetTemp

type KeysetTemp struct {
	Id          string
	Unit        string
	Active      bool
	Keys        map[uint64]json.RawMessage
	InputFeePpk uint
}

type KeysetsMap

type KeysetsMap map[string]map[string]WalletKeyset

KeysetsMap maps a mint url to map of string keyset id to keyset

type MintKeyset added in v0.2.0

type MintKeyset struct {
	Id                string
	Unit              string
	Active            bool
	DerivationPathIdx uint32
	Keys              map[uint64]KeyPair
	InputFeePpk       uint
}

func GenerateKeyset

func GenerateKeyset(master *hdkeychain.ExtendedKey, index uint32, inputFeePpk uint) (*MintKeyset, error)

func (*MintKeyset) DerivePublic added in v0.2.0

func (ks *MintKeyset) DerivePublic() map[uint64]string

DerivePublic returns the keyset's public keys as a map of amounts uint64 to strings that represents the public key

func (*MintKeyset) MarshalJSON added in v0.2.0

func (ks *MintKeyset) MarshalJSON() ([]byte, error)

func (*MintKeyset) UnmarshalJSON added in v0.2.0

func (ks *MintKeyset) UnmarshalJSON(data []byte) error

type WalletKeyset added in v0.2.0

type WalletKeyset struct {
	Id          string
	MintURL     string
	Unit        string
	Active      bool
	PublicKeys  map[uint64]*secp256k1.PublicKey
	Counter     uint32
	InputFeePpk uint
}

func (*WalletKeyset) MarshalJSON added in v0.2.0

func (wk *WalletKeyset) MarshalJSON() ([]byte, error)

func (*WalletKeyset) UnmarshalJSON added in v0.2.0

func (wk *WalletKeyset) UnmarshalJSON(data []byte) error

type WalletKeysetTemp added in v0.2.0

type WalletKeysetTemp struct {
	Id          string
	MintURL     string
	Unit        string
	Active      bool
	PublicKeys  map[uint64][]byte
	Counter     uint32
	InputFeePpk uint
}

Jump to

Keyboard shortcuts

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