cashu

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: 9 Imported by: 3

Documentation

Overview

Package cashu contains the core structs and logic of the Cashu protocol.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTokenV3 = errors.New("invalid V3 token")
	ErrInvalidTokenV4 = errors.New("invalid V4 token")
	ErrInvalidUnit    = errors.New("invalid unit")
)
View Source
var (
	StandardErr                  = Error{Detail: "mint is currently unable to process request", Code: StandardErrCode}
	EmptyBodyErr                 = Error{Detail: "request body cannot be emtpy", Code: StandardErrCode}
	UnknownKeysetErr             = Error{Detail: "unknown keyset", Code: UnknownKeysetErrCode}
	PaymentMethodNotSupportedErr = Error{Detail: "payment method not supported", Code: PaymentMethodErrCode}
	UnitNotSupportedErr          = Error{Detail: "unit not supported", Code: UnitErrCode}
	InvalidBlindedMessageAmount  = Error{Detail: "invalid amount in blinded message", Code: StandardErrCode}
	BlindedMessageAlreadySigned  = Error{Detail: "blinded message already signed", Code: BlindedMessageAlreadySignedErrCode}
	MintQuoteRequestNotPaid      = Error{Detail: "quote request has not been paid", Code: MintQuoteRequestNotPaidErrCode}
	MintQuoteAlreadyIssued       = Error{Detail: "quote already issued", Code: MintQuoteAlreadyIssuedErrCode}
	MintingDisabled              = Error{Detail: "minting is disabled", Code: MintingDisabledErrCode}
	MintAmountExceededErr        = Error{Detail: "max amount for minting exceeded", Code: AmountLimitExceeded}
	OutputsOverQuoteAmountErr    = Error{Detail: "sum of the output amounts is greater than quote amount", Code: StandardErrCode}
	ProofAlreadyUsedErr          = Error{Detail: "proof already used", Code: ProofAlreadyUsedErrCode}
	ProofPendingErr              = Error{Detail: "proof is pending", Code: ProofAlreadyUsedErrCode}
	InvalidProofErr              = Error{Detail: "invalid proof", Code: InvalidProofErrCode}
	NoProofsProvided             = Error{Detail: "no proofs provided", Code: InvalidProofErrCode}
	DuplicateProofs              = Error{Detail: "duplicate proofs", Code: InvalidProofErrCode}
	QuoteNotExistErr             = Error{Detail: "quote does not exist", Code: MeltQuoteErrCode}
	MeltQuotePending             = Error{Detail: "quote is pending", Code: MeltQuotePendingErrCode}
	MeltQuoteAlreadyPaid         = Error{Detail: "quote already paid", Code: MeltQuoteAlreadyPaidErrCode}
	MeltAmountExceededErr        = Error{Detail: "max amount for melting exceeded", Code: AmountLimitExceeded}
	MeltQuoteForRequestExists    = Error{Detail: "melt quote for payment request already exists", Code: MeltQuoteErrCode}
	InsufficientProofsAmount     = Error{
		Detail: "amount of input proofs is below amount needed for transaction",
		Code:   InsufficientProofAmountErrCode,
	}
	InactiveKeysetSignatureRequest = Error{Detail: "requested signature from inactive keyset", Code: InactiveKeysetErrCode}
)

Functions

func AmountSplit

func AmountSplit(amount uint64) []uint64

Given an amount, it returns list of amounts e.g 13 -> [1, 4, 8] that can be used to build blinded messages or split operations. from nutshell implementation

func CheckDuplicateProofs added in v0.2.0

func CheckDuplicateProofs(proofs Proofs) bool

func Count added in v0.2.0

func Count(amounts []uint64, amount uint64) uint

func GenerateRandomQuoteId added in v0.2.0

func GenerateRandomQuoteId() (string, error)

func Max added in v0.2.0

func Max(x, y uint64) uint64

func SortBlindedMessages added in v0.2.0

func SortBlindedMessages(blindedMessages BlindedMessages, secrets []string, rs []*secp256k1.PrivateKey)

Types

type BlindedMessage

type BlindedMessage struct {
	Amount  uint64 `json:"amount"`
	B_      string `json:"B_"`
	Id      string `json:"id"`
	Witness string `json:"witness,omitempty"`
}

Cashu BlindedMessage. See https://github.com/cashubtc/nuts/blob/main/00.md#blindedmessage

func NewBlindedMessage added in v0.2.0

func NewBlindedMessage(id string, amount uint64, B_ *secp256k1.PublicKey) BlindedMessage

type BlindedMessages

type BlindedMessages []BlindedMessage

func (BlindedMessages) Amount added in v0.2.0

func (bm BlindedMessages) Amount() uint64

type BlindedSignature

type BlindedSignature struct {
	Amount uint64 `json:"amount"`
	C_     string `json:"C_"`
	Id     string `json:"id"`
	// doing pointer here so that omitempty works.
	// an empty struct would still get marshalled
	DLEQ *DLEQProof `json:"dleq,omitempty"`
}

Cashu BlindedSignature. See https://github.com/cashubtc/nuts/blob/main/00.md#blindsignature

type BlindedSignatures

type BlindedSignatures []BlindedSignature

func (BlindedSignatures) Amount added in v0.3.0

func (bs BlindedSignatures) Amount() uint64

type CashuErrCode

type CashuErrCode int
const (
	StandardErrCode CashuErrCode = 10000
	// These will never be returned in a response.
	// Using them to identify internally where
	// the error originated and log appropriately
	DBErrCode               CashuErrCode = 1
	LightningBackendErrCode CashuErrCode = 2

	UnitErrCode                        CashuErrCode = 11005
	PaymentMethodErrCode               CashuErrCode = 11007
	BlindedMessageAlreadySignedErrCode CashuErrCode = 10002

	InvalidProofErrCode            CashuErrCode = 10003
	ProofAlreadyUsedErrCode        CashuErrCode = 11001
	InsufficientProofAmountErrCode CashuErrCode = 11002

	UnknownKeysetErrCode  CashuErrCode = 12001
	InactiveKeysetErrCode CashuErrCode = 12002

	AmountLimitExceeded            CashuErrCode = 11006
	MintQuoteRequestNotPaidErrCode CashuErrCode = 20001
	MintQuoteAlreadyIssuedErrCode  CashuErrCode = 20002
	MintingDisabledErrCode         CashuErrCode = 20003

	MeltQuotePendingErrCode     CashuErrCode = 20005
	MeltQuoteAlreadyPaidErrCode CashuErrCode = 20006
	LightningPaymentErrCode     CashuErrCode = 20008
	MeltQuoteErrCode            CashuErrCode = 20009
)

Common error codes

type DLEQProof added in v0.3.0

type DLEQProof struct {
	E string `json:"e"`
	S string `json:"s"`
	R string `json:"r,omitempty"`
}

type DLEQV4 added in v0.3.0

type DLEQV4 struct {
	E []byte `json:"e"`
	S []byte `json:"s"`
	R []byte `json:"r"`
}

type Error

type Error struct {
	Detail string       `json:"detail"`
	Code   CashuErrCode `json:"code"`
}

Error represents an error to be returned by the mint

func BuildCashuError

func BuildCashuError(detail string, code CashuErrCode) *Error

func (Error) Error

func (e Error) Error() string

type Proof

type Proof struct {
	Amount  uint64 `json:"amount"`
	Id      string `json:"id"`
	Secret  string `json:"secret"`
	C       string `json:"C"`
	Witness string `json:"witness,omitempty"`
	// doing pointer here so that omitempty works.
	// an empty struct would still get marshalled
	DLEQ *DLEQProof `json:"dleq,omitempty"`
}

Cashu Proof. See https://github.com/cashubtc/nuts/blob/main/00.md#proof

type ProofV4 added in v0.3.0

type ProofV4 struct {
	Amount  uint64  `json:"a"`
	Secret  string  `json:"s"`
	C       []byte  `json:"c"`
	Witness string  `json:"w,omitempty"`
	DLEQ    *DLEQV4 `json:"d,omitempty"`
}

type Proofs

type Proofs []Proof

func (Proofs) Amount

func (proofs Proofs) Amount() uint64

Amount returns the total amount from the array of Proof

type Token

type Token interface {
	Proofs() Proofs
	Mint() string
	Amount() uint64
	Serialize() (string, error)
}

Cashu token. See https://github.com/cashubtc/nuts/blob/main/00.md#token-format

func DecodeToken

func DecodeToken(tokenstr string) (Token, error)

type TokenV3 added in v0.3.0

type TokenV3 struct {
	Token []TokenV3Proof `json:"token"`
	Unit  string         `json:"unit"`
	Memo  string         `json:"memo,omitempty"`
}

func DecodeTokenV3 added in v0.3.0

func DecodeTokenV3(tokenstr string) (*TokenV3, error)

func NewTokenV3 added in v0.3.0

func NewTokenV3(proofs Proofs, mint string, unit Unit, includeDLEQ bool) (TokenV3, error)

func (TokenV3) Amount added in v0.3.0

func (t TokenV3) Amount() uint64

func (TokenV3) Mint added in v0.3.0

func (t TokenV3) Mint() string

func (TokenV3) Proofs added in v0.3.0

func (t TokenV3) Proofs() Proofs

func (TokenV3) Serialize added in v0.3.0

func (t TokenV3) Serialize() (string, error)

type TokenV3Proof added in v0.3.0

type TokenV3Proof struct {
	Mint   string `json:"mint"`
	Proofs Proofs `json:"proofs"`
}

type TokenV4 added in v0.3.0

type TokenV4 struct {
	TokenProofs []TokenV4Proof `json:"t"`
	Memo        string         `json:"d,omitempty"`
	MintURL     string         `json:"m"`
	Unit        string         `json:"u"`
}

func DecodeTokenV4 added in v0.3.0

func DecodeTokenV4(tokenstr string) (*TokenV4, error)

func NewTokenV4 added in v0.3.0

func NewTokenV4(proofs Proofs, mint string, unit Unit, includeDLEQ bool) (TokenV4, error)

func (TokenV4) Amount added in v0.3.0

func (t TokenV4) Amount() uint64

func (TokenV4) Mint added in v0.3.0

func (t TokenV4) Mint() string

func (TokenV4) Proofs added in v0.3.0

func (t TokenV4) Proofs() Proofs

func (TokenV4) Serialize added in v0.3.0

func (t TokenV4) Serialize() (string, error)

type TokenV4Proof added in v0.3.0

type TokenV4Proof struct {
	Id     []byte    `json:"i"`
	Proofs []ProofV4 `json:"p"`
}

type Unit added in v0.3.0

type Unit int
const (
	Sat Unit = iota

	BOLT11_METHOD = "bolt11"
)

func (Unit) String added in v0.3.0

func (unit Unit) String() string

Directories

Path Synopsis
nuts
nut01
Package nut01 contains structs as defined in NUT-01 [NUT-01]: https://github.com/cashubtc/nuts/blob/main/01.md
Package nut01 contains structs as defined in NUT-01 [NUT-01]: https://github.com/cashubtc/nuts/blob/main/01.md
nut02
Package nut02 contains structs as defined in NUT-02 [NUT-02]: https://github.com/cashubtc/nuts/blob/main/02.md
Package nut02 contains structs as defined in NUT-02 [NUT-02]: https://github.com/cashubtc/nuts/blob/main/02.md
nut03
Package nut03 contains structs as defined in NUT-03 [NUT-03]: https://github.com/cashubtc/nuts/blob/main/03.md
Package nut03 contains structs as defined in NUT-03 [NUT-03]: https://github.com/cashubtc/nuts/blob/main/03.md
nut04
Package nut04 contains structs as defined in NUT-04 [NUT-04]: https://github.com/cashubtc/nuts/blob/main/04.md
Package nut04 contains structs as defined in NUT-04 [NUT-04]: https://github.com/cashubtc/nuts/blob/main/04.md
nut05
Package nut05 contains structs as defined in NUT-05 [NUT-05]: https://github.com/cashubtc/nuts/blob/main/05.md
Package nut05 contains structs as defined in NUT-05 [NUT-05]: https://github.com/cashubtc/nuts/blob/main/05.md
nut06
Package nut06 contains structs as defined in NUT-06 [NUT-06]: https://github.com/cashubtc/nuts/blob/main/06.md
Package nut06 contains structs as defined in NUT-06 [NUT-06]: https://github.com/cashubtc/nuts/blob/main/06.md

Jump to

Keyboard shortcuts

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