cashu

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: 4 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}
	KeysetNotExistErr            = Error{Detail: "keyset does not exist", Code: KeysetErrCode}
	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: KeysetErrCode}
	QuoteIdNotSpecifiedErr       = Error{Detail: "quote id not specified", Code: QuoteErrCode}
	InvoiceNotExistErr           = Error{Detail: "invoice does not exist", Code: InvoiceErrCode}
	InvoiceNotPaidErr            = Error{Detail: "invoice has not been paid", Code: InvoiceErrCode}
	OutputsOverInvoiceErr        = Error{
		Detail: "sum of the output amounts is greater than amount of invoice paid",
		Code:   InvoiceErrCode}
	InvoiceTokensIssuedErr   = Error{Detail: "tokens already issued for invoice", Code: InvoiceErrCode}
	ProofAlreadyUsedErr      = Error{Detail: "proofs already used", Code: ProofsErrCode}
	InvalidProofErr          = Error{Detail: "invalid proof", Code: ProofsErrCode}
	AmountsDoNotMatch        = Error{Detail: "amounts do not match", Code: ProofsErrCode}
	MeltQuoteNotExistErr     = Error{Detail: "melt quote does not exist", Code: QuoteErrCode}
	InsufficientProofsAmount = Error{Detail: "insufficient amount in proofs", Code: ProofsErrCode}
	InvalidKeysetProof       = Error{Detail: "proof from an invalid keyset", Code: ProofsErrCode}
	InvalidSignatureRequest  = Error{Detail: "requested signature from non-active keyset", Code: KeysetErrCode}
)

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

Types

type BlindedMessage

type BlindedMessage struct {
	Amount uint64 `json:"amount"`
	B_     string `json:"B_"`
	Id     string `json:"id"`

	// including Witness field for now to avoid throwing error when parsing json
	// from clients that include this field even when mint does not support it.
	Witness string `json:"witness,omitempty"`
}

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

type BlindedMessages

type BlindedMessages []BlindedMessage

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 = 1000 + iota
	KeysetErrCode
	PaymentMethodErrCode
	UnitErrCode
	QuoteErrCode
	InvoiceErrCode
	ProofsErrCode
)

Common error codes

type Error

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

Error represents an error to be used 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"`

	// including Witness field for now to avoid throwing error when parsing json
	// from clients that include this field even when mint does not support it.
	Witness string `json:"witness,omitempty"`
}

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

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