crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 10 Imported by: 6

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_"

Variables

This section is empty.

Functions

func BlindMessage

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

B_ = Y + rG

func BlindMessageDeprecated

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

func DeriveKeysetId

func DeriveKeysetId(keyset map[uint64]KeyPair) 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 HashToCurve

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

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

func HashToCurveDeprecated

func HashToCurveDeprecated(message []byte) *secp256k1.PublicKey

func SignBlindedMessage

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

C_ = kB_

func UnblindSignature

C = C_ - rK

func Verify

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

k * HashToCurve(secret) == C

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 Keyset

type Keyset struct {
	Id      string
	MintURL string
	Unit    string
	Active  bool
	Keys    map[uint64]KeyPair
}

func GenerateKeyset

func GenerateKeyset(seed, derivationPath string) *Keyset

func (*Keyset) DerivePublic

func (ks *Keyset) 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 (*Keyset) MarshalJSON

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

func (*Keyset) UnmarshalJSON

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

type KeysetTemp

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

type KeysetsMap

type KeysetsMap map[string]map[string]Keyset

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

Jump to

Keyboard shortcuts

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