Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cashurpc #6

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.mint.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MINT_DERIVATION_PATH="0/0/0"
MINT_NAME="a cashu mint"
MINT_DESCRIPTION="short mint description"
MINT_DESCRIPTION_LONG="a long description of the mint"
MINT_CONTACT_INFO=[["email", "contact@me.com"], ["nostr", "npub..."]]
MINT_CONTACT_INFO=[{"type":2, "info":"npub...."},{"type":0, "info":"contact@me.com"}]
MINT_MOTD="message to the users of the mint"

# Lightning Backend
Expand Down
4 changes: 0 additions & 4 deletions .env.wallet.example
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# mint to connect to
MINT_HOST=127.0.0.1
MINT_PORT=3338
#MINT_URL=http://localhost:3338
Empty file added .gitignore
Empty file.
86 changes: 9 additions & 77 deletions cashu/cashu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,31 @@
package cashu

import (
cashurpc "buf.build/gen/go/cashu/rpc/protocolbuffers/go"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
)

// Cashu BlindedMessage. See https://github.com/cashubtc/nuts/blob/main/00.md#blindedmessage
type BlindedMessage struct {
Amount uint64 `json:"amount"`
B_ string `json:"B_"`
Id string `json:"id"`
type BlindedMessages []*cashurpc.BlindedMessage

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

type BlindedMessages []BlindedMessage

// Cashu BlindedSignature. See https://github.com/cashubtc/nuts/blob/main/00.md#blindsignature
type BlindedSignature struct {
Amount uint64 `json:"amount"`
C_ string `json:"C_"`
Id string `json:"id"`
}

type BlindedSignatures []BlindedSignature

// Cashu Proof. See https://github.com/cashubtc/nuts/blob/main/00.md#proof
type Proof struct {
Amount uint64 `json:"amount"`
Id string `json:"id"`
Secret string `json:"secret"`
C string `json:"C"`
type BlindedSignatures []*cashurpc.BlindedSignature

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

type Proofs []Proof

// Amount returns the total amount from
// the array of Proof
func (proofs Proofs) Amount() uint64 {
func Amount(proofs []*cashurpc.Proof) uint64 {
var totalAmount uint64 = 0
for _, proof := range proofs {
totalAmount += proof.Amount
}
return totalAmount
}

// Cashu token. See https://github.com/cashubtc/nuts/blob/main/00.md#token-format
type Token struct {
Token []TokenProof `json:"token"`
Unit string `json:"unit"`
Memo string `json:"memo,omitempty"`
}

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

func NewToken(proofs Proofs, mint string, unit string) Token {
tokenProof := TokenProof{Mint: mint, Proofs: proofs}
return Token{Token: []TokenProof{tokenProof}, Unit: unit}
func NewToken(proofs []*cashurpc.Proof, mint string, unit string) cashurpc.TokenV3 {
tokenProof := cashurpc.BaseToken{Mint: mint, Proofs: proofs}
return cashurpc.TokenV3{Token: []*cashurpc.BaseToken{&tokenProof}, Unit: unit}
}

func DecodeToken(tokenstr string) (*Token, error) {
func DecodeToken(tokenstr string) (*cashurpc.TokenV3, error) {
prefixVersion := tokenstr[:6]
base64Token := tokenstr[6:]
if prefixVersion != "cashuA" {
Expand All @@ -89,7 +44,7 @@ func DecodeToken(tokenstr string) (*Token, error) {
}
}

var token Token
var token cashurpc.TokenV3
err = json.Unmarshal(tokenBytes, &token)
if err != nil {
return nil, fmt.Errorf("error unmarshaling token: %v", err)
Expand All @@ -98,29 +53,6 @@ func DecodeToken(tokenstr string) (*Token, error) {
return &token, nil
}

// ToString serializes the token to a string
func (t *Token) ToString() string {
jsonBytes, err := json.Marshal(t)
if err != nil {
panic(err)
}

token := base64.URLEncoding.EncodeToString(jsonBytes)
return "cashuA" + token
}

// TotalAmount returns the total amount
// from the array of Proofs in the token
func (t *Token) TotalAmount() uint64 {
var totalAmount uint64 = 0
for _, tokenProof := range t.Token {
for _, proof := range tokenProof.Proofs {
totalAmount += proof.Amount
}
}
return totalAmount
}

type CashuErrCode int

// Error represents an error to be returned by the mint
Expand Down
62 changes: 0 additions & 62 deletions cashu/nuts/nut01/nut01.go

This file was deleted.

14 changes: 0 additions & 14 deletions cashu/nuts/nut02/nut02.go

This file was deleted.

15 changes: 0 additions & 15 deletions cashu/nuts/nut03/nut03.go

This file was deleted.

27 changes: 0 additions & 27 deletions cashu/nuts/nut04/nut04.go

This file was deleted.

29 changes: 0 additions & 29 deletions cashu/nuts/nut05/nut05.go

This file was deleted.

75 changes: 0 additions & 75 deletions cashu/nuts/nut06/nut06.go

This file was deleted.

Loading