Skip to content

Commit

Permalink
wallet client calls for signature restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
elnosh committed Jun 20, 2024
1 parent 9a44f28 commit c66c8b8
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cashu/nuts/nut07/nut07.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nut07

type State int

const (
Unspent State = iota
Pending
Spent
)

func (state State) String() string {
switch state {
case Unspent:
return "UNSPENT"
case Pending:
return "PENDING"
case Spent:
return "SPENT"
default:
return "unknown"
}
}

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

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

type ProofState struct {
Y string `json:"Y"`
State State `json:"state"`
Witness string `json:"witness"`
}
12 changes: 12 additions & 0 deletions cashu/nuts/nut09/nut09.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package nut09

import "github.com/elnosh/gonuts/cashu"

type PostRestoreRequest struct {
Outputs cashu.BlindedMessages `json:"outputs"`
}

type PostRestoreResponse struct {
Outputs cashu.BlindedMessages `json:"outputs"`
Signatures cashu.BlindedSignatures `json:"signatures"`
}
65 changes: 65 additions & 0 deletions wallet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ import (
"github.com/elnosh/gonuts/cashu/nuts/nut03"
"github.com/elnosh/gonuts/cashu/nuts/nut04"
"github.com/elnosh/gonuts/cashu/nuts/nut05"
"github.com/elnosh/gonuts/cashu/nuts/nut06"
"github.com/elnosh/gonuts/cashu/nuts/nut07"
"github.com/elnosh/gonuts/cashu/nuts/nut09"
)

func GetMintInfo(mintURL string) (*nut06.MintInfo, error) {
resp, err := get(mintURL + "/v1/info")
if err != nil {
return nil, err
}
defer resp.Body.Close()

var mintInfo *nut06.MintInfo
err = json.NewDecoder(resp.Body).Decode(&mintInfo)
if err != nil {
return nil, fmt.Errorf("json.Decode: %v", err)
}

return mintInfo, nil
}

func GetActiveKeysets(mintURL string) (*nut01.GetKeysResponse, error) {
resp, err := get(mintURL + "/v1/keys")
if err != nil {
Expand Down Expand Up @@ -190,6 +209,52 @@ func PostMeltBolt11(mintURL string, meltRequest nut05.PostMeltBolt11Request) (
return meltResponse, nil
}

func PostCheckProofState(mintURL string, stateRequest nut07.PostCheckStateRequest) (
*nut07.PostCheckStateResponse, error) {

requestBody, err := json.Marshal(stateRequest)
if err != nil {
return nil, fmt.Errorf("json.Marshal: %v", err)
}

resp, err := httpPost(mintURL+"/v1/checkstate", "application/json", bytes.NewBuffer(requestBody))
if err != nil {
return nil, err
}
defer resp.Body.Close()

var stateResponse *nut07.PostCheckStateResponse
err = json.NewDecoder(resp.Body).Decode(&stateResponse)
if err != nil {
return nil, fmt.Errorf("json.Decode: %v", err)
}

return stateResponse, nil
}

func PostRestore(mintURL string, restoreRequest nut09.PostRestoreRequest) (
*nut09.PostRestoreResponse, error) {

requestBody, err := json.Marshal(restoreRequest)
if err != nil {
return nil, fmt.Errorf("json.Marshal: %v", err)
}

resp, err := httpPost(mintURL+"/v1/restore", "application/json", bytes.NewBuffer(requestBody))
if err != nil {
return nil, err
}
defer resp.Body.Close()

var restoreResponse *nut09.PostRestoreResponse
err = json.NewDecoder(resp.Body).Decode(&restoreResponse)
if err != nil {
return nil, fmt.Errorf("json.Decode: %v", err)
}

return restoreResponse, nil
}

func get(url string) (*http.Response, error) {
resp, err := http.Get(url)
if err != nil {
Expand Down

0 comments on commit c66c8b8

Please sign in to comment.