cashu

package
v0.0.0-...-3a97ad1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OUTPUT_BLINDED_MESSAGE_ALREADY_SIGNED = 10002
	TOKEN_NOT_VERIFIED                    = 10003

	TOKEN_ALREADY_SPENT      = 11001
	TRANSACTION_NOT_BALANCED = 11002
	UNIT_NOT_SUPPORTED       = 11005
	INSUFICIENT_FEE          = 11006
	// AMOUNT_OUTSIDE_OF_LIMIT = 11006
	OVERPAID_FEE = 11007

	KEYSET_NOT_KNOW = 12001
	INACTIVE_KEYSET = 12002

	REQUEST_NOT_PAID     = 20001
	TOKEN_ALREADY_ISSUED = 20002
	MINTING_DISABLED     = 20003
	QUOTE_PENDING        = 20005
	INVOICE_ALREADY_PAID = 20006

	UNKNOWN = 99999
)
View Source
const ExpiryMinutesDefault int64 = 15
View Source
const MaxKeysetAmount int = 64

Variables

View Source
var (
	ErrInvalidSpendCondition         = errors.New("Invalid spend condition")
	ErrConvertSpendConditionToString = errors.New("Failed to convert spend condition to string")
	ErrInvalidTagName                = errors.New("Invalid tag name")
	ErrConvertTagToString            = errors.New("Failed to convert tag to string")
	ErrInvalidTagValue               = errors.New("Invalid tag value")
	ErrInvalidSigFlag                = errors.New("Invalid sig flag")
	ErrConvertSigFlagToString        = errors.New("Failed to convert sig flag to string")
	ErrMalformedTag                  = errors.New("Malformed tag")
	ErrCouldNotParseSpendCondition   = errors.New("Could not parse spend condition")
	ErrCouldNotParseWitness          = errors.New("Could not parse witness")
	ErrEmptyWitness                  = errors.New("Witness is empty")
	ErrNoValidSignatures             = errors.New("No valid signatures found")
	ErrNotEnoughSignatures           = errors.New("Not enough signatures")
	ErrLocktimePassed                = errors.New("Locktime has passed and no refund key was found")
	ErrInvalidHexPreimage            = errors.New("Preimage is not a valid hex string")
	ErrInvalidPreimage               = errors.New("Invalid preimage")
)
View Source
var (
	ErrCouldNotParseUnitString = errors.New("Could not parse unit string")
	ErrCouldNotEncryptSeed     = errors.New("Could not encrypt seed")
	ErrCouldNotDecryptSeed     = errors.New("Could not decrypt seed")
	ErrKeysetNotFound          = errors.New("Keyset not found")
	ErrKeysetForProofNotFound  = errors.New("Keyset for proof not found")
)
View Source
var AvailableSeeds []Unit = []Unit{Sat}

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 DeriveKeysetId

func DeriveKeysetId(keysets []Keyset) (string, error)

func ExpiryTime

func ExpiryTime() int64

func Fees

func Fees(proofs []Proof, keysets []Keyset) (int, error)

func GetAmountsForKeysets

func GetAmountsForKeysets() []uint64

Types

type ACTION_STATE

type ACTION_STATE string
const (
	UNPAID  ACTION_STATE = "UNPAID"
	PENDING ACTION_STATE = "PENDING"
	ISSUED  ACTION_STATE = "ISSUED"
)

type BasicKeysetResponse

type BasicKeysetResponse struct {
	Id          string `json:"id"`
	Unit        string `json:"unit"`
	Active      bool   `json:"active"`
	InputFeePpk int    `json:"input_fee_ppk"`
}

type BlindSignature

type BlindSignature struct {
	Amount uint64              `json:"amount"`
	Id     string              `json:"id"`
	C_     string              `json:"C_"`
	Dleq   *BlindSignatureDLEQ `json:"dleq"`
}

func (*BlindSignature) GenerateDLEQ

func (b *BlindSignature) GenerateDLEQ(B_ *secp256k1.PublicKey, a *secp256k1.PrivateKey) error

func (*BlindSignature) VerifyDLEQ

func (b *BlindSignature) VerifyDLEQ(
	blindMessage *secp256k1.PublicKey,
	e *secp256k1.PrivateKey,
	s *secp256k1.PrivateKey,
	A *secp256k1.PublicKey,
) (bool, error)

R1 = s*G - e*A

R2 = s*B' - e*C' e == hash(R1,R2,A,C')

If true, a in A = a*G must be equal to a in C' = a*B'

type BlindSignatureDLEQ

type BlindSignatureDLEQ struct {
	E *secp256k1.PrivateKey `json:"e"`
	S *secp256k1.PrivateKey `json:"s"`
}

func (*BlindSignatureDLEQ) MarshalJSON

func (b *BlindSignatureDLEQ) MarshalJSON() ([]byte, error)

func (*BlindSignatureDLEQ) UnmarshalJSON

func (b *BlindSignatureDLEQ) UnmarshalJSON(data []byte) error

type BlindedMessage

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

func (BlindedMessage) GenerateBlindSignature

func (b BlindedMessage) GenerateBlindSignature(k *secp256k1.PrivateKey) (BlindSignature, error)

func (BlindedMessage) VerifyBlindMessageSignature

func (b BlindedMessage) VerifyBlindMessageSignature(pubkeys map[*btcec.PublicKey]bool) error

type CheckState

type CheckState struct {
	Y       string     `json:"Y"`
	State   ProofState `json:"state"`
	Witness *string    `json:"witness"`
}

type ContactInfo

type ContactInfo struct {
	Method string `json:"method"`
	Info   string `json:"info"`
}

type ErrorCode

type ErrorCode int

func (ErrorCode) String

func (e ErrorCode) String() string

type ErrorResponse

type ErrorResponse struct {
	// integer code
	Code ErrorCode
	// Human readable error
	Error string
	// Extended explanation of error
	Detail *string
}

func ErrorCodeToResponse

func ErrorCodeToResponse(code ErrorCode, detail *string) ErrorResponse

type GetInfoResponse

type GetInfoResponse struct {
	Name            string                  `json:"name"`
	Version         string                  `json:"version"`
	Pubkey          string                  `json:"pubkey"`
	Description     string                  `json:"description"`
	DescriptionLong string                  `json:"description_long"`
	Contact         []ContactInfo           `json:"contact"`
	Motd            string                  `json:"motd"`
	Nuts            map[string]SwapMintInfo `json:"nuts"`
}

type KeysResponse

type KeysResponse map[string][]KeysetResponse

func OrderKeysetByUnit

func OrderKeysetByUnit(keysets []Keyset) KeysResponse

type Keyset

type Keyset struct {
	Id          string                `json:"id"`
	Active      bool                  `json:"active" db:"active"`
	Unit        string                `json:"unit"`
	Amount      uint64                `json:"amount"`
	PrivKey     *secp256k1.PrivateKey `json:"priv_key"`
	CreatedAt   int64                 `json:"created_at"`
	InputFeePpk int                   `json:"input_fee_ppk"`
}

func GenerateKeysets

func GenerateKeysets(masterKey *bip32.Key, values []uint64, id string, unit Unit, inputFee int) ([]Keyset, error)

func (*Keyset) GetPubKey

func (keyset *Keyset) GetPubKey() *secp256k1.PublicKey

type KeysetResponse

type KeysetResponse struct {
	Id          string            `json:"id"`
	Unit        string            `json:"unit"`
	Keys        map[string]string `json:"keys"`
	InputFeePpk int               `json:"input_fee_ppk"`
}

type MeltRequestDB

type MeltRequestDB struct {
	Quote      string `json:"quote"`
	Unit       string `json:"unit"`
	Expiry     int64  `json:"expiry"`
	Amount     uint64 `json:"amount"`
	FeeReserve uint64 `json:"fee_reserve" db:"fee_reserve"`
	// Deprecated: Should be removed after all main wallets change to the new State format
	RequestPaid     bool         `json:"paid" db:"request_paid"`
	Request         string       `json:"request"`
	Melted          bool         `json:"melted"`
	State           ACTION_STATE `json:"state"`
	PaymentPreimage string       `json:"payment_preimage"`
}

func (*MeltRequestDB) GetPostMeltQuoteResponse

func (meltRequest *MeltRequestDB) GetPostMeltQuoteResponse() PostMeltQuoteBolt11Response

type MintError

type MintError struct {
	Detail string `json:"detail"`
	Code   int8   `json:"code"`
}

type PostCheckStateRequest

type PostCheckStateRequest struct {
	Ys []string `json:"Ys"`
}

type PostCheckStateResponse

type PostCheckStateResponse struct {
	States []CheckState `json:"states"`
}

type PostMeltBolt11Request

type PostMeltBolt11Request struct {
	Quote   string           `json:"quote"`
	Inputs  []Proof          `json:"inputs"`
	Outputs []BlindedMessage `json:"outputs"`
}

type PostMeltQuoteBolt11Request

type PostMeltQuoteBolt11Request struct {
	Request string `json:"request"`
	Unit    string `json:"unit"`
}

type PostMeltQuoteBolt11Response

type PostMeltQuoteBolt11Response struct {
	Quote      string `json:"quote"`
	Amount     uint64 `json:"amount"`
	FeeReserve uint64 `json:"fee_reserve"`
	// Deprecated: Should be removed after all main wallets change to the new State format
	Paid            bool             `json:"paid"`
	Expiry          int64            `json:"expiry"`
	State           ACTION_STATE     `json:"state"`
	Change          []BlindSignature `json:"change"`
	PaymentPreimage string           `json:"payment_preimage"`
}

type PostMintBolt11Request

type PostMintBolt11Request struct {
	Quote   string           `json:"quote"`
	Outputs []BlindedMessage `json:"outputs"`
}

type PostMintBolt11Response

type PostMintBolt11Response struct {
	Signatures []BlindSignature `json:"signatures"`
}

type PostMintQuoteBolt11Request

type PostMintQuoteBolt11Request struct {
	Amount int64  `json:"amount"`
	Unit   string `json:"unit"`
}

type PostMintQuoteBolt11Response

type PostMintQuoteBolt11Response struct {
	Quote   string `json:"quote"`
	Request string `json:"request"`
	// Deprecated: Should be removed after all main wallets change to the new State format
	RequestPaid bool         `json:"paid" db:"request_paid"`
	Expiry      int64        `json:"expiry"`
	Unit        string       `json:"unit"`
	Minted      bool         `json:"minted"`
	State       ACTION_STATE `json:"state"`
}

type PostRestoreRequest

type PostRestoreRequest struct {
	Outputs []BlindedMessage `json:"outputs"`
}

type PostRestoreResponse

type PostRestoreResponse struct {
	Outputs    []BlindedMessage `json:"outputs"`
	Signatures []BlindSignature `json:"signatures"`
}

type PostSwapRequest

type PostSwapRequest struct {
	Inputs  []Proof          `json:"inputs"`
	Outputs []BlindedMessage `json:"outputs"`
}

type PostSwapResponse

type PostSwapResponse struct {
	Signatures []BlindSignature `json:"signatures"`
}

type Proof

type Proof struct {
	Amount  uint64 `json:"amount"`
	Id      string `json:"id"`
	Secret  string `json:"secret"`
	C       string `json:"C" db:"c"`
	Y       string `json:"Y" db:"Y"`
	Witness string `json:"witness" db:"witness"`
}

func (*Proof) AddPreimage

func (p *Proof) AddPreimage(preimage string) error

func (Proof) HashSecretToCurve

func (p Proof) HashSecretToCurve() (Proof, error)

func (Proof) IsProofSpendConditioned

func (p Proof) IsProofSpendConditioned(checkOutputs *bool) (bool, *SpendCondition, *Witness, error)

func (*Proof) Sign

func (p *Proof) Sign(privkey *secp256k1.PrivateKey) error

func (Proof) VerifyWitness

func (p Proof) VerifyWitness(spendCondition *SpendCondition, witness *Witness, pubkeysFromProofs *map[*btcec.PublicKey]bool) (bool, error)

type ProofState

type ProofState string
const PROOF_PENDING ProofState = "PENDING"
const PROOF_SPENT ProofState = "SPENT"
const PROOF_UNSPENT ProofState = "UNSPENT"

type RecoverSigDB

type RecoverSigDB struct {
	Amount    uint64 `json:"amount"`
	Id        string `json:"id"`
	B_        string `json:"B_" db:"B_"`
	C_        string `json:"C_" db:"C_"`
	CreatedAt int64  `json:"created_at" db:"created_at"`
	Witness   string `json:"witness"`
}

func (RecoverSigDB) GetBlindSignature

func (r RecoverSigDB) GetBlindSignature() BlindSignature

func (RecoverSigDB) GetBlindedMessage

func (r RecoverSigDB) GetBlindedMessage() BlindedMessage

func (RecoverSigDB) GetSigAndMessage

func (r RecoverSigDB) GetSigAndMessage() (BlindSignature, BlindedMessage)

type Seed

type Seed struct {
	Seed        []byte
	Active      bool
	CreatedAt   int64
	Version     int
	Unit        string
	Id          string
	Encrypted   bool
	InputFeePpk int `json:"input_fee_ppk" db:"input_fee_ppk"`
}

func DeriveIndividualSeedFromKey

func DeriveIndividualSeedFromKey(keyFromMint string, version int, unit Unit) (Seed, error)

func DeriveSeedsFromKey

func DeriveSeedsFromKey(keyFromMint string, version int, availableSeeds []Unit) ([]Seed, error)

func SetUpSeedAndKeyset

func SetUpSeedAndKeyset(masterKey *bip32.Key, version int, unit Unit) (Seed, error)

func (*Seed) DecryptSeed

func (seed *Seed) DecryptSeed(mintPrivateKey string) error

func (*Seed) EncryptSeed

func (seed *Seed) EncryptSeed(mintPrivateKey string) error

type SigFlag

type SigFlag int
const (
	SigAll    SigFlag = iota + 1
	SigInputs SigFlag = iota + 2
)

func SigFlagFromString

func SigFlagFromString(s string) (SigFlag, error)

func (SigFlag) String

func (sf SigFlag) String() string

type SpendCondition

type SpendCondition struct {
	Type SpendConditionType
	Data SpendConditionData
}

func (*SpendCondition) MarshalJSON

func (sc *SpendCondition) MarshalJSON() ([]byte, error)

["P2PK",{"nonce":"3229136a6627050449e85dcdf90315f87519f172b2af80b2e1d460695db511ab","data":"0275c5c0ddafea52d669f09de48da03896d09962d6d4e545e94f573d52840f04ae"}]

func (*SpendCondition) String

func (sc *SpendCondition) String() (string, error)

func (*SpendCondition) UnmarshalJSON

func (s *SpendCondition) UnmarshalJSON(b []byte) error

func (*SpendCondition) VerifyPreimage

func (sc *SpendCondition) VerifyPreimage(witness *Witness) error

func (*SpendCondition) VerifySignatures

func (sc *SpendCondition) VerifySignatures(witness *Witness, message string) (bool, []*btcec.PublicKey, error)

type SpendConditionData

type SpendConditionData struct {
	Nonce string
	Data  string
	Tags  TagsInfo
}

type SpendConditionType

type SpendConditionType int
const (
	P2PK SpendConditionType = iota + 1
	HTLC SpendConditionType = iota + 2
)

func (SpendConditionType) String

func (sc SpendConditionType) String() (string, error)

func (*SpendConditionType) UnmarshalJSON

func (sc *SpendConditionType) UnmarshalJSON(b []byte) error

type SwapMintInfo

type SwapMintInfo struct {
	Methods   *[]SwapMintMethod `json:"methods,omitempty"`
	Disabled  *bool             `json:"disabled,omitempty"`
	Supported *bool             `json:"supported,omitempty"`
}

type SwapMintMethod

type SwapMintMethod struct {
	Method    string `json:"method"`
	Unit      string `json:"unit"`
	MinAmount int    `json:"min_amount"`
	MaxAmount int    `json:"max_amount"`
}

type Tags

type Tags int
const (
	Sigflag  Tags = iota + 1
	Pubkeys  Tags = iota + 2
	NSigs    Tags = iota + 3
	Locktime Tags = iota + 4
	Refund   Tags = iota + 5
)

func TagFromString

func TagFromString(s string) (Tags, error)

func (Tags) String

func (t Tags) String() string

type TagsInfo

type TagsInfo struct {
	Sigflag  SigFlag
	Pubkeys  []*btcec.PublicKey
	NSigs    int
	Locktime int
	Refund   []*btcec.PublicKey
}

func (*TagsInfo) UnmarshalJSON

func (tags *TagsInfo) UnmarshalJSON(b []byte) error

type Unit

type Unit int
const Msat Unit = iota + 2
const Sat Unit = iota + 1

func UnitFromString

func UnitFromString(s string) (Unit, error)

func (Unit) EnumIndex

func (d Unit) EnumIndex() int

EnumIndex - Creating common behavior - give the type a EnumIndex functio

func (Unit) String

func (d Unit) String() string

String - Creating common behavior - give the type a String function

type Witness

type Witness struct {
	Preimage   string `json:"preimage,omitempty"`
	Signatures []*schnorr.Signature
}

func (*Witness) String

func (wit *Witness) String() (string, error)

func (*Witness) UnmarshalJSON

func (wit *Witness) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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