cashu

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: MIT Imports: 8 Imported by: 7

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	StandardErr                  = Error{Detail: "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}
	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: MintAmountExceededErrCode}
	OutputsOverQuoteAmountErr    = Error{Detail: "sum of the output amounts is greater than quote amount", Code: StandardErrCode}
	ProofAlreadyUsedErr          = Error{Detail: "proofs already used", 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: QuoteErrCode}
	MeltQuoteAlreadyPaid         = Error{Detail: "quote already paid", Code: MeltQuoteAlreadyPaidErrCode}
	MeltAmountExceededErr        = Error{Detail: "max amount for melting exceeded", Code: MeltAmountExceededErrCode}
	InsufficientProofsAmount     = Error{
		Detail: "amount of input proofs is below amount needed for transaction",
		Code:   InsufficientProofAmountErrCode,
	}
	InactiveKeysetSignatureRequest = Error{Detail: "requested signature from non-active 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"`
}

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

type BlindedSignatures

type BlindedSignatures []BlindedSignature

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 = 11006

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

	UnknownKeysetErrCode  CashuErrCode = 12001
	InactiveKeysetErrCode CashuErrCode = 12002

	MintQuoteRequestNotPaidErrCode CashuErrCode = 20001
	MintQuoteAlreadyIssuedErrCode  CashuErrCode = 20002
	MintingDisabledErrCode         CashuErrCode = 20003
	MintAmountExceededErrCode      CashuErrCode = 20004

	MeltQuotePendingErrCode     CashuErrCode = 20005
	MeltQuoteAlreadyPaidErrCode CashuErrCode = 20006
	MeltAmountExceededErrCode   CashuErrCode = 20007

	QuoteErrCode CashuErrCode = 20008
)

Common error codes

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"`
}

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

func (Proof) IsSecretP2PK added in v0.2.0

func (p Proof) IsSecretP2PK() bool

func (Proof) SecretType added in v0.2.0

func (p Proof) SecretType() SecretKind

type Proofs

type Proofs []Proof

func (Proofs) Amount

func (proofs Proofs) Amount() uint64

Amount returns the total amount from the array of Proof

type SecretKind added in v0.2.0

type SecretKind int
const (
	Random SecretKind = iota
	P2PK
)

func (SecretKind) String added in v0.2.0

func (kind SecretKind) String() string

type Token

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

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

func DecodeToken

func DecodeToken(tokenstr string) (*Token, error)

func NewToken

func NewToken(proofs Proofs, mint string, unit string) Token

func (*Token) ToString

func (t *Token) ToString() string

ToString serializes the token to a string

func (*Token) TotalAmount

func (t *Token) TotalAmount() uint64

TotalAmount returns the total amount from the array of Proofs in the token

type TokenProof

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

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